Python tornado.httputil.RequestStartLine() Examples
The following are 30
code examples of tornado.httputil.RequestStartLine().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
tornado.httputil
, or try the search function
.
Example #1
Source File: simple_httpclient.py From teleport with Apache License 2.0 | 6 votes |
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")
Example #2
Source File: http1connection.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
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
Example #3
Source File: simple_httpclient.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 6 votes |
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")
Example #4
Source File: simple_httpclient.py From opendevops with GNU General Public License v3.0 | 6 votes |
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")
Example #5
Source File: routing.py From teleport with Apache License 2.0 | 6 votes |
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)
Example #6
Source File: http1connection.py From opendevops with GNU General Public License v3.0 | 6 votes |
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
Example #7
Source File: http1connection.py From teleport with Apache License 2.0 | 6 votes |
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
Example #8
Source File: http1connection.py From teleport with Apache License 2.0 | 6 votes |
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
Example #9
Source File: stream.py From tornado_http2 with Apache License 2.0 | 6 votes |
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
Example #10
Source File: simple_httpclient.py From teleport with Apache License 2.0 | 6 votes |
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")
Example #11
Source File: web.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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
Example #12
Source File: server.py From tornado_http2 with Apache License 2.0 | 5 votes |
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()
Example #13
Source File: server.py From tornado_http2 with Apache License 2.0 | 5 votes |
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)
Example #14
Source File: stream.py From tornado_http2 with Apache License 2.0 | 5 votes |
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)
Example #15
Source File: httpserver.py From teleport with Apache License 2.0 | 5 votes |
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
Example #16
Source File: httpserver.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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
Example #17
Source File: httpserver.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
def headers_received( self, start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine], headers: httputil.HTTPHeaders, ) -> Optional[Awaitable[None]]: # TODO: either make context an official part of the # HTTPConnection interface or figure out some other way to do this. self.connection.context._apply_xheaders(headers) # type: ignore return self.delegate.headers_received(start_line, headers)
Example #18
Source File: websocket.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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)
Example #19
Source File: http1connection.py From V1EngineeringInc-Docs with Creative Commons Attribution Share Alike 4.0 International | 5 votes |
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)
Example #20
Source File: websocket.py From teleport with Apache License 2.0 | 5 votes |
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)
Example #21
Source File: web.py From opendevops with GNU General Public License v3.0 | 5 votes |
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
Example #22
Source File: web.py From teleport with Apache License 2.0 | 5 votes |
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
Example #23
Source File: http1connection.py From teleport with Apache License 2.0 | 5 votes |
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)
Example #24
Source File: websocket.py From teleport with Apache License 2.0 | 5 votes |
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)
Example #25
Source File: httpserver.py From teleport with Apache License 2.0 | 5 votes |
def headers_received( self, start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine], headers: httputil.HTTPHeaders, ) -> Optional[Awaitable[None]]: # TODO: either make context an official part of the # HTTPConnection interface or figure out some other way to do this. self.connection.context._apply_xheaders(headers) # type: ignore return self.delegate.headers_received(start_line, headers)
Example #26
Source File: httpserver.py From teleport with Apache License 2.0 | 5 votes |
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
Example #27
Source File: web.py From teleport with Apache License 2.0 | 5 votes |
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
Example #28
Source File: http1connection.py From opendevops with GNU General Public License v3.0 | 5 votes |
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)
Example #29
Source File: websocket.py From opendevops with GNU General Public License v3.0 | 5 votes |
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)
Example #30
Source File: httpserver.py From opendevops with GNU General Public License v3.0 | 5 votes |
def headers_received( self, start_line: Union[httputil.RequestStartLine, httputil.ResponseStartLine], headers: httputil.HTTPHeaders, ) -> Optional[Awaitable[None]]: # TODO: either make context an official part of the # HTTPConnection interface or figure out some other way to do this. self.connection.context._apply_xheaders(headers) # type: ignore return self.delegate.headers_received(start_line, headers)