本文整理汇总了Python中tornado.http1connection.HTTP1Connection方法的典型用法代码示例。如果您正苦于以下问题:Python http1connection.HTTP1Connection方法的具体用法?Python http1connection.HTTP1Connection怎么用?Python http1connection.HTTP1Connection使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类tornado.http1connection
的用法示例。
在下文中一共展示了http1connection.HTTP1Connection方法的8个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: read_stream_body
# 需要导入模块: from tornado import http1connection [as 别名]
# 或者: from tornado.http1connection import HTTP1Connection [as 别名]
def read_stream_body(stream, callback):
"""Reads an HTTP response from `stream` and runs callback with its
headers and body."""
chunks = []
class Delegate(HTTPMessageDelegate):
def headers_received(self, start_line, headers):
self.headers = headers
def data_received(self, chunk):
chunks.append(chunk)
def finish(self):
callback((self.headers, b''.join(chunks)))
conn = HTTP1Connection(stream, True)
conn.read_response(Delegate())
示例2: test_http10_no_content_length
# 需要导入模块: from tornado import http1connection [as 别名]
# 或者: from tornado.http1connection import HTTP1Connection [as 别名]
def test_http10_no_content_length(self):
# Regression test for a bug in which can_keep_alive would crash
# for an HTTP/1.0 (not 1.1) response with no content-length.
conn = HTTP1Connection(self.client_stream, True)
self.server_stream.write(b"HTTP/1.0 200 Not Modified\r\n\r\nhello")
self.server_stream.close()
event = Event()
test = self
body = []
class Delegate(HTTPMessageDelegate):
def headers_received(self, start_line, headers):
test.code = start_line.code
def data_received(self, data):
body.append(data)
def finish(self):
event.set()
yield conn.read_response(Delegate())
yield event.wait()
self.assertEqual(self.code, 200)
self.assertEqual(b"".join(body), b"hello")
示例3: read_stream_body
# 需要导入模块: from tornado import http1connection [as 别名]
# 或者: from tornado.http1connection import HTTP1Connection [as 别名]
def read_stream_body(stream):
"""Reads an HTTP response from `stream` and returns a tuple of its
start_line, headers and body."""
chunks = []
class Delegate(HTTPMessageDelegate):
def headers_received(self, start_line, headers):
self.headers = headers
self.start_line = start_line
def data_received(self, chunk):
chunks.append(chunk)
def finish(self):
conn.detach() # type: ignore
conn = HTTP1Connection(stream, True)
delegate = Delegate()
await conn.read_response(delegate)
return delegate.start_line, delegate.headers, b"".join(chunks)
示例4: test_http10_no_content_length
# 需要导入模块: from tornado import http1connection [as 别名]
# 或者: from tornado.http1connection import HTTP1Connection [as 别名]
def test_http10_no_content_length(self):
# Regression test for a bug in which can_keep_alive would crash
# for an HTTP/1.0 (not 1.1) response with no content-length.
conn = HTTP1Connection(self.client_stream, True)
self.server_stream.write(b"HTTP/1.0 200 Not Modified\r\n\r\nhello")
self.server_stream.close()
event = Event()
test = self
body = []
class Delegate(HTTPMessageDelegate):
def headers_received(self, start_line, headers):
test.code = start_line.code
def data_received(self, data):
body.append(data)
def finish(self):
event.set()
yield conn.read_response(Delegate())
yield event.wait()
self.assertEqual(self.code, 200)
self.assertEqual(b''.join(body), b'hello')
示例5: read_stream_body
# 需要导入模块: from tornado import http1connection [as 别名]
# 或者: from tornado.http1connection import HTTP1Connection [as 别名]
def read_stream_body(stream, callback):
"""Reads an HTTP response from `stream` and runs callback with its
start_line, headers and body."""
chunks = []
class Delegate(HTTPMessageDelegate):
def headers_received(self, start_line, headers):
self.headers = headers
self.start_line = start_line
def data_received(self, chunk):
chunks.append(chunk)
def finish(self):
conn.detach()
callback((self.start_line, self.headers, b''.join(chunks)))
conn = HTTP1Connection(stream, True)
conn.read_response(Delegate())
示例6: init_request_handler
# 需要导入模块: from tornado import http1connection [as 别名]
# 或者: from tornado.http1connection import HTTP1Connection [as 别名]
def init_request_handler(self, rh_cls, view_type):
global app
if view_type == 'list':
rq = rh_cls.as_list()
elif view_type == 'detail':
rq = rh_cls.as_detail()
# compose a fake incoming request
fake_connection = None
# after tornado 4.1, it's not allowed to build a RequestHandler without a connection.
if _newer_or_equal_((4, 0, 0, 0)):
ios = IOStream(socket.socket(socket.AF_INET, socket.SOCK_STREAM, 0))
context = None
# there is a bug in these 2 version that would fail when
# context is None
if _equal_((4, 0, 1)) or _equal_((4, 0, 2)):
context = httpserver._HTTPRequestContext(ios, None, None)
fake_connection = HTTP1Connection(ios, False, context=context)
fake_request = httpserver.HTTPRequest('GET', '/fake', body='test123', connection=fake_connection)
self.new_handler = rq(app, fake_request)
示例7: _create_connection
# 需要导入模块: from tornado import http1connection [as 别名]
# 或者: from tornado.http1connection import HTTP1Connection [as 别名]
def _create_connection(self, stream):
stream.set_nodelay(True)
connection = HTTP1Connection(
stream, True,
HTTP1ConnectionParameters(
no_keep_alive=True,
max_header_size=self.max_header_size,
max_body_size=self.max_body_size,
decompress=self.request.decompress_response),
self._sockaddr)
return connection
示例8: _create_connection
# 需要导入模块: from tornado import http1connection [as 别名]
# 或者: from tornado.http1connection import HTTP1Connection [as 别名]
def _create_connection(self, stream: IOStream) -> HTTP1Connection:
stream.set_nodelay(True)
connection = HTTP1Connection(
stream,
True,
HTTP1ConnectionParameters(
no_keep_alive=True,
max_header_size=self.max_header_size,
max_body_size=self.max_body_size,
decompress=bool(self.request.decompress_response),
),
self._sockaddr,
)
return connection