本文整理汇总了Python中tornado.httputil.ResponseStartLine方法的典型用法代码示例。如果您正苦于以下问题:Python httputil.ResponseStartLine方法的具体用法?Python httputil.ResponseStartLine怎么用?Python httputil.ResponseStartLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.httputil
的用法示例。
在下文中一共展示了httputil.ResponseStartLine方法的14个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: respond_204
# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import ResponseStartLine [as 别名]
def respond_204(self, request):
self.http1 = request.version.startswith('HTTP/1.')
if not self.http1:
# Close the request cleanly in HTTP/2; it will be skipped anyway.
request.connection.write_headers(ResponseStartLine('', 200, 'OK'),
HTTPHeaders())
request.connection.finish()
return
# A 204 response never has a body, even if doesn't have a content-length
# (which would otherwise mean read-until-close). Tornado always
# sends a content-length, so we simulate here a server that sends
# no content length and does not close the connection.
#
# Tests of a 204 response with a Content-Length header are included
# in SimpleHTTPClientTestMixin.
stream = request.connection.detach()
stream.write(
b"HTTP/1.1 204 No content\r\n\r\n")
stream.close()
示例2: headers_received
# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import ResponseStartLine [as 别名]
def headers_received(
self,
first_line: Union[httputil.ResponseStartLine, httputil.RequestStartLine],
headers: httputil.HTTPHeaders,
) -> None:
assert isinstance(first_line, httputil.ResponseStartLine)
if self.request.expect_100_continue and first_line.code == 100:
await self._write_body(False)
return
self.code = first_line.code
self.reason = first_line.reason
self.headers = headers
if self._should_follow_redirect():
return
if self.request.header_callback is not None:
# Reassemble the start line.
self.request.header_callback("%s %s %s\r\n" % first_line)
for k, v in self.headers.get_all():
self.request.header_callback("%s: %s\r\n" % (k, v))
self.request.header_callback("\r\n")
示例3: headers_received
# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import ResponseStartLine [as 别名]
def headers_received(
self,
start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine],
headers: httputil.HTTPHeaders,
) -> Optional[Awaitable[None]]:
assert isinstance(start_line, httputil.RequestStartLine)
request = httputil.HTTPServerRequest(
connection=self.request_conn,
server_connection=self.server_conn,
start_line=start_line,
headers=headers,
)
self.delegate = self.router.find_handler(request)
if self.delegate is None:
app_log.debug(
"Delegate for %s %s request not found",
start_line.method,
start_line.path,
)
self.delegate = _DefaultMessageDelegate(self.request_conn)
return self.delegate.headers_received(start_line, headers)
示例4: respond_204
# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import ResponseStartLine [as 别名]
def respond_204(self, request):
self.http1 = request.version.startswith('HTTP/1.')
if not self.http1:
# Close the request cleanly in HTTP/2; it will be skipped anyway.
request.connection.write_headers(ResponseStartLine('', 200, 'OK'),
HTTPHeaders())
request.connection.finish()
return
# A 204 response never has a body, even if doesn't have a content-length
# (which would otherwise mean read-until-close). We simulate here a
# server that sends no content length and does not close the connection.
#
# Tests of a 204 response with no Content-Length header are included
# in SimpleHTTPClientTestMixin.
stream = request.connection.detach()
stream.write(b"HTTP/1.1 204 No content\r\n")
if request.arguments.get("error", [False])[-1]:
stream.write(b"Content-Length: 5\r\n")
else:
stream.write(b"Content-Length: 0\r\n")
stream.write(b"\r\n")
stream.close()
示例5: _check_header_length
# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import ResponseStartLine [as 别名]
def _check_header_length(self):
if (sum(len(f.data) for f in self._header_frames) >
self.conn.params.max_header_size):
if self.conn.is_client:
# TODO: Need tests for client side of headers-too-large.
# What's the best way to send an error?
self.delegate.on_connection_close()
else:
# write_headers needs a start line so it can tell
# whether this is a HEAD or not. If we're rejecting
# the headers we can't know so just make something up.
# Note that this means the error response body MUST be
# zero bytes so it doesn't matter whether the client
# sent a HEAD or a GET.
self._request_start_line = RequestStartLine('GET', '/', 'HTTP/2.0')
start_line = ResponseStartLine('HTTP/2.0', 431, 'Headers too large')
self.write_headers(start_line, HTTPHeaders())
self.finish()
return
示例6: __call__
# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import ResponseStartLine [as 别名]
def __call__(self, request):
data = {}
response = []
def start_response(status, response_headers, exc_info=None):
data["status"] = status
data["headers"] = response_headers
return response.append
app_response = self.wsgi_application(
WSGIContainer.environ(request), start_response)
try:
response.extend(app_response)
body = b"".join(response)
finally:
if hasattr(app_response, "close"):
app_response.close()
if not data:
raise Exception("WSGI app did not call start_response")
status_code, reason = data["status"].split(' ', 1)
status_code = int(status_code)
headers = data["headers"]
header_set = set(k.lower() for (k, v) in headers)
body = escape.utf8(body)
if status_code != 304:
if "content-length" not in header_set:
headers.append(("Content-Length", str(len(body))))
if "content-type" not in header_set:
headers.append(("Content-Type", "text/html; charset=UTF-8"))
if "server" not in header_set:
headers.append(("Server", "TornadoServer/%s" % tornado.version))
start_line = httputil.ResponseStartLine("HTTP/1.1", status_code, reason)
header_obj = httputil.HTTPHeaders()
for key, value in headers:
header_obj.add(key, value)
request.connection.write_headers(start_line, header_obj, chunk=body)
request.connection.finish()
self._log(status_code, request)
示例7: respond_100
# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import ResponseStartLine [as 别名]
def respond_100(self, request):
self.http1 = request.version.startswith('HTTP/1.')
if not self.http1:
request.connection.write_headers(ResponseStartLine('', 200, 'OK'),
HTTPHeaders())
request.connection.finish()
return
self.request = request
self.request.connection.stream.write(
b"HTTP/1.1 100 CONTINUE\r\n\r\n",
self.respond_200)
示例8: headers_received
# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import ResponseStartLine [as 别名]
def headers_received(
self,
start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine],
headers: httputil.HTTPHeaders,
) -> Optional[Awaitable[None]]:
if self.stream_request_body:
self.request._body_future = Future()
return self.execute()
return None
示例9: headers_received
# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import ResponseStartLine [as 别名]
def headers_received(
self,
start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine],
headers: httputil.HTTPHeaders,
) -> Optional[Awaitable[None]]:
self.request = httputil.HTTPServerRequest(
connection=self.connection,
start_line=typing.cast(httputil.RequestStartLine, start_line),
headers=headers,
)
return None
示例10: finish
# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import ResponseStartLine [as 别名]
def finish(self) -> None:
self.connection.write_headers(
httputil.ResponseStartLine("HTTP/1.1", 404, "Not Found"),
httputil.HTTPHeaders(),
)
self.connection.finish()
# _RuleList can either contain pre-constructed Rules or a sequence of
# arguments to be passed to the Rule constructor.
示例11: headers_received
# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import ResponseStartLine [as 别名]
def headers_received(
self,
start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine],
headers: httputil.HTTPHeaders,
) -> Optional[Awaitable[None]]:
if headers.get("Content-Encoding") == "gzip":
self._decompressor = GzipDecompressor()
# Downstream delegates will only see uncompressed data,
# so rename the content-encoding header.
# (but note that curl_httpclient doesn't do this).
headers.add("X-Consumed-Content-Encoding", headers["Content-Encoding"])
del headers["Content-Encoding"]
return self._delegate.headers_received(start_line, headers)
示例12: finish
# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import ResponseStartLine [as 别名]
def finish(self):
self.connection.write_headers(
httputil.ResponseStartLine("HTTP/1.1", 404, "Not Found"), httputil.HTTPHeaders())
self.connection.finish()
示例13: respond_100
# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import ResponseStartLine [as 别名]
def respond_100(self, request):
self.http1 = request.version.startswith('HTTP/1.')
if not self.http1:
request.connection.write_headers(ResponseStartLine('', 200, 'OK'),
HTTPHeaders())
request.connection.finish()
return
self.request = request
fut = self.request.connection.stream.write(
b"HTTP/1.1 100 CONTINUE\r\n\r\n")
fut.add_done_callback(self.respond_200)
示例14: headers_received
# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import ResponseStartLine [as 别名]
def headers_received(
self,
start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine],
headers: httputil.HTTPHeaders,
) -> None:
assert isinstance(start_line, httputil.ResponseStartLine)
if start_line.code != 101:
await super(WebSocketClientConnection, self).headers_received(
start_line, headers
)
return
if self._timeout is not None:
self.io_loop.remove_timeout(self._timeout)
self._timeout = None
self.headers = headers
self.protocol = self.get_websocket_protocol()
self.protocol._process_server_headers(self.key, self.headers)
self.protocol.stream = self.connection.detach()
IOLoop.current().add_callback(self.protocol._receive_frame_loop)
self.protocol.start_pinging()
# Once we've taken over the connection, clear the final callback
# we set on the http request. This deactivates the error handling
# in simple_httpclient that would otherwise interfere with our
# ability to see exceptions.
self.final_callback = None # type: ignore
future_set_result_unless_cancelled(self.connect_future, self)