Team Ai
Datasetpublic

codekingpro/portable-devtools

sourceHugging Faceupdated 5mo agoView on Hugging Face
1likes15kdownloads
_hooks.py123 linesDownload Raw Back to http
1from dataclasses import dataclass2 3from mitmproxy import http4from mitmproxy.proxy import commands5 6 7@dataclass8class HttpRequestHeadersHook(commands.StartHook):9    """10    HTTP request headers were successfully read. At this point, the body is empty.11    """12 13    name = "requestheaders"14    flow: http.HTTPFlow15 16 17@dataclass18class HttpRequestHook(commands.StartHook):19    """20    The full HTTP request has been read.21 22    Note: If request streaming is active, this event fires after the entire body has been streamed.23    HTTP trailers, if present, have not been transmitted to the server yet and can still be modified.24    Enabling streaming may cause unexpected event sequences: For example, `response` may now occur25    before `request` because the server replied with "413 Payload Too Large" during upload.26    """27 28    name = "request"29    flow: http.HTTPFlow30 31 32@dataclass33class HttpResponseHeadersHook(commands.StartHook):34    """35    HTTP response headers were successfully read. At this point, the body is empty.36    """37 38    name = "responseheaders"39    flow: http.HTTPFlow40 41 42@dataclass43class HttpResponseHook(commands.StartHook):44    """45    The full HTTP response has been read.46 47    Note: If response streaming is active, this event fires after the entire body has been streamed.48    HTTP trailers, if present, have not been transmitted to the client yet and can still be modified.49    """50 51    name = "response"52    flow: http.HTTPFlow53 54 55@dataclass56class HttpErrorHook(commands.StartHook):57    """58    An HTTP error has occurred, e.g. invalid server responses, or59    interrupted connections. This is distinct from a valid server HTTP60    error response, which is simply a response with an HTTP error code.61 62    Every flow will receive either an error or an response event, but not both.63    """64 65    name = "error"66    flow: http.HTTPFlow67 68 69@dataclass70class HttpConnectHook(commands.StartHook):71    """72    An HTTP CONNECT request was received. This event can be ignored for most practical purposes.73 74    This event only occurs in regular and upstream proxy modes75    when the client instructs mitmproxy to open a connection to an upstream host.76    Setting a non 2xx response on the flow will return the response to the client and abort the connection.77 78    CONNECT requests are HTTP proxy instructions for mitmproxy itself79    and not forwarded. They do not generate the usual HTTP handler events,80    but all requests going over the newly opened connection will.81    """82 83    flow: http.HTTPFlow84 85 86@dataclass87class HttpConnectUpstreamHook(commands.StartHook):88    """89    An HTTP CONNECT request is about to be sent to an upstream proxy.90    This event can be ignored for most practical purposes.91 92    This event can be used to set custom authentication headers for upstream proxies.93 94    CONNECT requests do not generate the usual HTTP handler events,95    but all requests going over the newly opened connection will.96    """97 98    flow: http.HTTPFlow99 100 101@dataclass102class HttpConnectedHook(commands.StartHook):103    """104    HTTP CONNECT was successful105 106    > [!WARNING]107    > This may fire before an upstream connection has been established108    > if `connection_strategy` is set to `lazy` (default)109    """110 111    flow: http.HTTPFlow112 113 114@dataclass115class HttpConnectErrorHook(commands.StartHook):116    """117    HTTP CONNECT has failed.118    This can happen when the upstream server is unreachable or proxy authentication is required.119    In contrast to the `error` hook, `flow.error` is not guaranteed to be set.120    """121 122    flow: http.HTTPFlow123 
codekingpro/portable-devtools · Team Ai