proxy.http package#
Subpackages#
Submodules#
Module contents#
proxy.py#
⚡⚡⚡ Fast, Lightweight, Pluggable, TLS interception capable proxy server focused on Network monitoring, controls & Application development, testing, debugging.
- copyright
2013-present by Abhinav Singh and contributors.
- license
BSD, see LICENSE for more details.
- class proxy.http.HttpClientConnection(conn: Union[ssl.SSLSocket, socket.socket], addr: Optional[Tuple[str, int]] = None)[source]#
Bases:
proxy.core.connection.client.TcpClientConnection
- _abc_impl = <_abc._abc_data object>#
- class proxy.http.HttpProtocolHandler(*args: Any, **kwargs: Any)[source]#
Bases:
proxy.core.base.tcp_server.BaseTcpServerHandler
[proxy.http.connection.HttpClientConnection
]HTTP, HTTPS, HTTP2, WebSockets protocol handler.
Accepts
Client
connection and delegates to HttpProtocolHandlerPlugin.- _abc_impl = <_abc._abc_data object>#
- _discover_plugin_klass(protocol: int) Optional[Type[proxy.http.plugin.HttpProtocolHandlerPlugin]] [source]#
Discovers and return matching HTTP handler plugin matching protocol.
- _initialize_plugin(klass: Type[proxy.http.plugin.HttpProtocolHandlerPlugin]) proxy.http.plugin.HttpProtocolHandlerPlugin [source]#
Initializes passed HTTP protocol handler plugin class.
- _parse_first_request(data: memoryview) bool [source]#
- static create(*args: Any) proxy.http.connection.HttpClientConnection [source]#
Implementations are responsible for creation of work objects from incoming args. This helps keep work core agnostic to creation of externally defined work class objects.
- async get_events() Dict[int, int] [source]#
Return sockets and events (read or write) that we are interested in.
- handle_data(data: memoryview) Optional[bool] [source]#
Handles incoming data from client.
- async handle_events(readables: List[int], writables: List[int]) bool [source]#
Returns True if proxy must tear down.
- initialize() None [source]#
Optionally upgrades connection to HTTPS, sets
conn
in non-blocking mode and initializes HTTP protocol plugins.
- class proxy.http.HttpProtocolHandlerPlugin(uid: str, flags: argparse.Namespace, client: proxy.http.connection.HttpClientConnection, request: proxy.http.parser.parser.HttpParser, event_queue: Optional[proxy.core.event.queue.EventQueue] = None, upstream_conn_pool: Optional[UpstreamConnectionPool] = None)[source]#
Bases:
proxy.http.descriptors.DescriptorsHandlerMixin
,abc.ABC
Base HttpProtocolHandler Plugin class.
NOTE: This is an internal plugin and in most cases only useful for core contributors. If you are looking for proxy server plugins see
<proxy.HttpProxyBasePlugin>
.Implements various lifecycle events for an accepted client connection. Following events are of interest:
Client Connection Accepted A new plugin instance is created per accepted client connection. Add your logic within __init__ constructor for any per connection setup.
Client Request Chunk Received on_client_data is called for every chunk of data sent by the client.
Client Request Complete on_request_complete is called once client request has completed.
Server Response Chunk Received on_response_chunk is called for every chunk received from the server.
Client Connection Closed Add your logic within
on_client_connection_close
for any per connection tear-down.
- _abc_impl = <_abc._abc_data object>#
- abstract on_client_connection_close() None [source]#
Client connection shutdown has been received, flush has been called, perform any cleanup work here.
- abstract on_client_data(raw: memoryview) None [source]#
Called only after original request has been completely received.
- abstract on_request_complete() Union[socket.socket, bool] [source]#
Called right after client request parser has reached COMPLETE state.
- abstract on_response_chunk(chunk: List[memoryview]) List[memoryview] [source]#
Handle data chunks as received from the server.
Return optionally modified chunk to return back to client.
- class proxy.http.Url(scheme: Optional[bytes] = None, username: Optional[bytes] = None, password: Optional[bytes] = None, hostname: Optional[bytes] = None, port: Optional[int] = None, remainder: Optional[bytes] = None)[source]#
Bases:
object
urllib.urlparse
doesn’t work for proxy.py, so we wrote a simple URL.Currently, URL only implements what is necessary for HttpParser to work.
- classmethod from_bytes(raw: bytes, allowed_url_schemes: Optional[List[bytes]] = None) proxy.http.url.Url [source]#
A URL within proxy.py core can have several styles, because proxy.py supports both proxy and web server use cases.
Example: For a Web server, url is like
/
or/get
or/get?key=value
For a HTTPS connect tunnel, url is likehttpbin.org:443
For a HTTP proxy request, url is likehttp://httpbin.org/get
proxy.py internally never expects a https scheme in the request line. But
Url
class provides support for parsing any scheme present in the URLs. e.g. ftp, icap etc.If a url with no scheme is parsed, e.g.
//host/abc.js
, then scheme defaults tohttp
.Further: 1) URL may contain unicode characters 2) URL may contain IPv4 and IPv6 format addresses instead of domain names