本文整理匯總了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)