本文整理汇总了Python中http.server.SimpleHTTPRequestHandler.do_HEAD方法的典型用法代码示例。如果您正苦于以下问题:Python SimpleHTTPRequestHandler.do_HEAD方法的具体用法?Python SimpleHTTPRequestHandler.do_HEAD怎么用?Python SimpleHTTPRequestHandler.do_HEAD使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类http.server.SimpleHTTPRequestHandler
的用法示例。
在下文中一共展示了SimpleHTTPRequestHandler.do_HEAD方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: do_HEAD
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_HEAD [as 别名]
def do_HEAD(self):
parsed_path = urllib.parse.urlparse(self.path)
if parsed_path.path.startswith("/echo"):
message = '\n'.join(
[
'CLIENT VALUES:',
'client_address=%s (%s)' % (self.client_address, self.address_string()),
'command=%s' % self.command,
'path=%s' % self.path,
'real path=%s' % parsed_path.path,
'query=%s' % parsed_path.query,
'request_version=%s' % self.request_version,
'',
'HEADERS:',
'%s' % self.headers,
]
)
self.send_response(200)
self.end_headers()
self.wfile.write(message.encode('utf-8'))
elif parsed_path.path.startswith("/redirect"):
self.send_response(301)
self.send_header('Location', "/echo")
self.end_headers()
else:
SimpleHTTPRequestHandler.do_HEAD(self)
return
示例2: do_HEAD
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_HEAD [as 别名]
def do_HEAD(self):
"""Serve a HEAD request."""
content = self._regenerate(self.path)
if content:
self._send_regenerated_head(content)
else:
SimpleHTTPRequestHandler.do_HEAD(self)
示例3: do_HEAD
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_HEAD [as 别名]
def do_HEAD(self):
if self.only_upgrade:
self.send_error(405, "Method Not Allowed")
else:
SimpleHTTPRequestHandler.do_HEAD(self)
示例4: do_HEAD
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_HEAD [as 别名]
def do_HEAD(self):
try:
SimpleHTTPRequestHandler.do_HEAD(self)
except Exception as e:
self.handle_exception(e)
示例5: do_HEAD
# 需要导入模块: from http.server import SimpleHTTPRequestHandler [as 别名]
# 或者: from http.server.SimpleHTTPRequestHandler import do_HEAD [as 别名]
def do_HEAD(self):
"""Serve a HEAD request."""
if not self.allow_path():
self.send_error(403)
else:
SimpleHTTPRequestHandler.do_HEAD(self)