當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。