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


Python httputil.RequestStartLine方法代码示例

本文整理汇总了Python中tornado.httputil.RequestStartLine方法的典型用法代码示例。如果您正苦于以下问题:Python httputil.RequestStartLine方法的具体用法?Python httputil.RequestStartLine怎么用?Python httputil.RequestStartLine使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在tornado.httputil的用法示例。


在下文中一共展示了httputil.RequestStartLine方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: headers_received

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import RequestStartLine [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") 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:24,代码来源:simple_httpclient.py

示例2: _can_keep_alive

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import RequestStartLine [as 别名]
def _can_keep_alive(
        self, start_line: httputil.RequestStartLine, headers: httputil.HTTPHeaders
    ) -> bool:
        if self.params.no_keep_alive:
            return False
        connection_header = headers.get("Connection")
        if connection_header is not None:
            connection_header = connection_header.lower()
        if start_line.version == "HTTP/1.1":
            return connection_header != "close"
        elif (
            "Content-Length" in headers
            or headers.get("Transfer-Encoding", "").lower() == "chunked"
            or getattr(start_line, "method", None) in ("HEAD", "GET")
        ):
            # start_line may be a request or response start line; only
            # the former has a method attribute.
            return connection_header == "keep-alive"
        return False 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:21,代码来源:http1connection.py

示例3: headers_received

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import RequestStartLine [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) 
开发者ID:tp4a,项目名称:teleport,代码行数:25,代码来源:routing.py

示例4: _check_header_length

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import RequestStartLine [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 
开发者ID:bdarnell,项目名称:tornado_http2,代码行数:21,代码来源:stream.py

示例5: headers_received

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import RequestStartLine [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 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:11,代码来源:web.py

示例6: headers_received

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import RequestStartLine [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 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:13,代码来源:httpserver.py

示例7: headers_received

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import RequestStartLine [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) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:33,代码来源:websocket.py

示例8: headers_received

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import RequestStartLine [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) 
开发者ID:opendevops-cn,项目名称:opendevops,代码行数:15,代码来源:http1connection.py

示例9: switch_protocols

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import RequestStartLine [as 别名]
def switch_protocols(self, callback):
        stream = self.conn.detach()
        stream.write(utf8(
            "HTTP/1.1 101 Switching Protocols\r\n"
            "Connection: Upgrade\r\n"
            "Upgrade: %s\r\n"
            "\r\n" % constants.HTTP2_CLEAR))
        h2_conn = Connection(stream, False, params=self.http2_params,
                             context=self.context)
        self.server._connections.add(h2_conn)
        h2_conn.start(self.server)
        self.conn = Stream(h2_conn, 1, None, context=self.context)
        h2_conn.streams[1] = self.conn
        self.conn._request_start_line = RequestStartLine(
            self._request_start_line.method,
            self._request_start_line.path,
            'HTTP/2.0')
        yield h2_conn._initial_settings_written

        if self.written_headers is not None:
            self.conn.write_headers(*self.written_headers)
        for write in self.written_chunks:
            self.conn.write(*write)
        if self.write_finished:
            self.conn.finish()
        if self.max_body_size is not None:
            self.conn.set_max_body_size(self.max_body_size)
        if self.body_timeout is not None:
            self.conn.set_body_timeout(self.body_timeout)
        if self.close_callback is not None:
            self.conn.set_close_callback(self.close_callback)
            self.close_callback = None
        self.upgrading = False

        try:
            callback()
        except Exception:
            app_log.error("Exception in callback", exc_info=True)
            self.conn.reset() 
开发者ID:bdarnell,项目名称:tornado_http2,代码行数:41,代码来源:server.py

示例10: headers_received

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import RequestStartLine [as 别名]
def headers_received(self, start_line, headers):
        if 'Upgrade' in headers:
            upgrades = set(i.strip() for i in headers['Upgrade'].split(','))
            if constants.HTTP2_CLEAR in upgrades:
                self.connection.upgrading = True
                start_line = RequestStartLine(
                    start_line.method, start_line.path, 'HTTP/2.0')
        self.connection._request_start_line = start_line
        return self.delegate.headers_received(start_line, headers) 
开发者ID:bdarnell,项目名称:tornado_http2,代码行数:11,代码来源:server.py

示例11: _start_request

# 需要导入模块: from tornado import httputil [as 别名]
# 或者: from tornado.httputil import RequestStartLine [as 别名]
def _start_request(self, pseudo_headers, headers):
        if "connection" in headers:
            raise ConnectionError(constants.ErrorCode.PROTOCOL_ERROR,
                                  "connection header should not be present")
        if "te" in headers and headers["te"] != "trailers":
            raise StreamError(self.stream_id, constants.ErrorCode.PROTOCOL_ERROR)
        if self.conn.is_client:
            status = int(pseudo_headers[':status'])
            start_line = ResponseStartLine('HTTP/2.0', status, responses.get(status, ''))
        else:
            for k in (':method', ':scheme', ':path'):
                if k not in pseudo_headers:
                    raise StreamError(self.stream_id,
                                      constants.ErrorCode.PROTOCOL_ERROR)
            start_line = RequestStartLine(pseudo_headers[':method'],
                                          pseudo_headers[':path'], 'HTTP/2.0')
            self._request_start_line = start_line

        if (self.conn.is_client and
            (self._request_start_line.method == 'HEAD' or
             start_line.code == 304)):
            self._incoming_content_remaining = 0
        elif "content-length" in headers:
            self._incoming_content_remaining = int(headers["content-length"])

        if not self.conn.is_client or status >= 200:
            self._phase = constants.HTTPPhase.BODY

        self._delegate_started = True
        self.delegate.headers_received(start_line, headers) 
开发者ID:bdarnell,项目名称:tornado_http2,代码行数:32,代码来源:stream.py


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