当前位置: 首页>>代码示例>>Python>>正文


Python http1connection.HTTP1Connection方法代码示例

本文整理汇总了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()) 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:18,代码来源:httpserver_test.py

示例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") 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:27,代码来源:http1connection_test.py

示例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) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:22,代码来源:httpserver_test.py

示例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') 
开发者ID:tp4a,项目名称:teleport,代码行数:27,代码来源:http1connection_test.py

示例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()) 
开发者ID:tp4a,项目名称:teleport,代码行数:20,代码来源:httpserver_test.py

示例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) 
开发者ID:toastdriven,项目名称:restless,代码行数:24,代码来源:test_tnd.py

示例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 
开发者ID:tao12345666333,项目名称:tornado-zh,代码行数:13,代码来源:simple_httpclient.py

示例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 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:16,代码来源:simple_httpclient.py


注:本文中的tornado.http1connection.HTTP1Connection方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。