mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
update docs, fix #215
This commit is contained in:
parent
fe58c1c6eb
commit
9cc10630c8
@ -76,25 +76,25 @@ The main classes you will deal with in writing mitmproxy scripts are:
|
|||||||
|
|
||||||
<table class="table">
|
<table class="table">
|
||||||
<tr>
|
<tr>
|
||||||
<th>libmproxy.flow.ClientConnection</th>
|
<th>libmproxy.proxy.server.ConnectionHandler</th>
|
||||||
|
<td>Describes a proxy client connection session. Always has a client_conn attribute, might have a server_conn attribute.</td>
|
||||||
|
</tr>
|
||||||
|
<tr>
|
||||||
|
<th>libmproxy.proxy.connection.ClientConnection</th>
|
||||||
<td>Describes a client connection.</td>
|
<td>Describes a client connection.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>libmproxy.flow.ClientDisconnection</th>
|
<th>libmproxy.proxy.connection.ServerConnection</th>
|
||||||
<td>Describes a client disconnection.</td>
|
<td>Describes a server connection.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>libmproxy.flow.Error</th>
|
<th>libmproxy.protocol.primitives.Error</th>
|
||||||
<td>A communications error.</td>
|
<td>A communications error.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>libmproxy.flow.Flow</th>
|
<th>libmproxy.protocol.http.HTTPFlow</th>
|
||||||
<td>A collection of objects representing a single HTTP transaction.</td>
|
<td>A collection of objects representing a single HTTP transaction.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
|
||||||
<th>libmproxy.flow.Headers</th>
|
|
||||||
<td>HTTP headers for a request or response.</td>
|
|
||||||
</tr>
|
|
||||||
<tr>
|
<tr>
|
||||||
<th>libmproxy.flow.ODict</th>
|
<th>libmproxy.flow.ODict</th>
|
||||||
|
|
||||||
@ -103,15 +103,15 @@ The main classes you will deal with in writing mitmproxy scripts are:
|
|||||||
calls (used mainly for headers).</td>
|
calls (used mainly for headers).</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>libmproxy.flow.Response</th>
|
<th>libmproxy.protocol.http.HTTPResponse</th>
|
||||||
<td>An HTTP response.</td>
|
<td>An HTTP response.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>libmproxy.flow.Request</th>
|
<th>libmproxy.protocol.http.HTTPRequest</th>
|
||||||
<td>An HTTP request.</td>
|
<td>An HTTP request.</td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<th>libmproxy.flow.ScriptContext</th>
|
<th>libmproxy.script.ScriptContext</th>
|
||||||
<td> A handle for interacting with mitmproxy's from within scripts. </td>
|
<td> A handle for interacting with mitmproxy's from within scripts. </td>
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
@ -124,7 +124,7 @@ The canonical API documentation is the code. You can view the API documentation
|
|||||||
using pydoc (which is installed with Python by default), like this:
|
using pydoc (which is installed with Python by default), like this:
|
||||||
|
|
||||||
<pre class="terminal">
|
<pre class="terminal">
|
||||||
> pydoc libmproxy.flow.Request
|
> pydoc libmproxy.protocol.http.HTTPRequest
|
||||||
</pre>
|
</pre>
|
||||||
|
|
||||||
|
|
||||||
|
@ -209,7 +209,7 @@ def common_options(parser):
|
|||||||
action="store", type = int, dest="port", default=8080,
|
action="store", type = int, dest="port", default=8080,
|
||||||
help = "Proxy service port."
|
help = "Proxy service port."
|
||||||
)
|
)
|
||||||
# We could make a mutually exclusive group out of -R, -F, -T, but we don't do because
|
# We could make a mutually exclusive group out of -R, -F, -T, but we don't do that because
|
||||||
# - --upstream-server should be in that group as well, but it's already in a different group.
|
# - --upstream-server should be in that group as well, but it's already in a different group.
|
||||||
# - our own error messages are more helpful
|
# - our own error messages are more helpful
|
||||||
parser.add_argument(
|
parser.add_argument(
|
||||||
|
@ -2,7 +2,7 @@ import os, sys, copy
|
|||||||
import urwid
|
import urwid
|
||||||
import common, grideditor, contentview
|
import common, grideditor, contentview
|
||||||
from .. import utils, flow, controller
|
from .. import utils, flow, controller
|
||||||
from ..protocol.http import CONTENT_MISSING
|
from ..protocol.http import HTTPResponse, CONTENT_MISSING
|
||||||
|
|
||||||
|
|
||||||
class SearchError(Exception): pass
|
class SearchError(Exception): pass
|
||||||
@ -571,7 +571,7 @@ class FlowView(common.WWrap):
|
|||||||
conn = self.flow.request
|
conn = self.flow.request
|
||||||
else:
|
else:
|
||||||
if not self.flow.response:
|
if not self.flow.response:
|
||||||
self.flow.response = flow.Response(
|
self.flow.response = HTTPResponse(
|
||||||
self.flow.request,
|
self.flow.request,
|
||||||
self.flow.request.httpversion,
|
self.flow.request.httpversion,
|
||||||
200, "OK", flow.ODictCaseless(), "", None
|
200, "OK", flow.ODictCaseless(), "", None
|
||||||
|
@ -1,4 +1,4 @@
|
|||||||
from libmproxy.proxy.primitives import AddressPriority
|
from ..proxy.primitives import AddressPriority
|
||||||
|
|
||||||
KILL = 0 # const for killed requests
|
KILL = 0 # const for killed requests
|
||||||
|
|
||||||
|
@ -1,10 +1,9 @@
|
|||||||
import socket
|
import socket
|
||||||
from .. import version, protocol
|
from OpenSSL import SSL
|
||||||
from libmproxy.proxy.primitives import Log
|
|
||||||
from .primitives import ProxyServerError
|
|
||||||
from .connection import ClientConnection, ServerConnection
|
|
||||||
from .primitives import ProxyError, ConnectionTypeChange, AddressPriority
|
|
||||||
from netlib import tcp
|
from netlib import tcp
|
||||||
|
from .primitives import ProxyServerError, Log, ProxyError, ConnectionTypeChange, AddressPriority
|
||||||
|
from .connection import ClientConnection, ServerConnection
|
||||||
|
from .. import version, protocol
|
||||||
|
|
||||||
|
|
||||||
class DummyServer:
|
class DummyServer:
|
||||||
@ -23,6 +22,7 @@ class DummyServer:
|
|||||||
class ProxyServer(tcp.TCPServer):
|
class ProxyServer(tcp.TCPServer):
|
||||||
allow_reuse_address = True
|
allow_reuse_address = True
|
||||||
bound = True
|
bound = True
|
||||||
|
|
||||||
def __init__(self, config, port, host='', server_version=version.NAMEVERSION):
|
def __init__(self, config, port, host='', server_version=version.NAMEVERSION):
|
||||||
"""
|
"""
|
||||||
Raises ProxyServerError if there's a startup problem.
|
Raises ProxyServerError if there's a startup problem.
|
||||||
@ -51,8 +51,11 @@ class ProxyServer(tcp.TCPServer):
|
|||||||
class ConnectionHandler:
|
class ConnectionHandler:
|
||||||
def __init__(self, config, client_connection, client_address, server, channel, server_version):
|
def __init__(self, config, client_connection, client_address, server, channel, server_version):
|
||||||
self.config = config
|
self.config = config
|
||||||
|
"""@type: libmproxy.proxy.config.ProxyConfig"""
|
||||||
self.client_conn = ClientConnection(client_connection, client_address, server)
|
self.client_conn = ClientConnection(client_connection, client_address, server)
|
||||||
|
"""@type: libmproxy.proxy.connection.ClientConnection"""
|
||||||
self.server_conn = None
|
self.server_conn = None
|
||||||
|
"""@type: libmproxy.proxy.connection.ServerConnection"""
|
||||||
self.channel, self.server_version = channel, server_version
|
self.channel, self.server_version = channel, server_version
|
||||||
|
|
||||||
self.close = False
|
self.close = False
|
||||||
@ -98,7 +101,7 @@ class ConnectionHandler:
|
|||||||
|
|
||||||
def del_server_connection(self):
|
def del_server_connection(self):
|
||||||
"""
|
"""
|
||||||
Deletes an existing server connection.
|
Deletes (and closes) an existing server connection.
|
||||||
"""
|
"""
|
||||||
if self.server_conn and self.server_conn.connection:
|
if self.server_conn and self.server_conn.connection:
|
||||||
self.server_conn.finish()
|
self.server_conn.finish()
|
||||||
@ -150,8 +153,7 @@ class ConnectionHandler:
|
|||||||
"""
|
"""
|
||||||
Establishes SSL on the existing connection(s) to the server or the client,
|
Establishes SSL on the existing connection(s) to the server or the client,
|
||||||
as specified by the parameters. If the target server is on the pass-through list,
|
as specified by the parameters. If the target server is on the pass-through list,
|
||||||
the conntype attribute will be changed and the SSL connection won't be wrapped.
|
the conntype attribute will be changed and a ConnTypeChanged exception will be raised.
|
||||||
A protocol handler must raise a ConnTypeChanged exception if it detects that this is happening
|
|
||||||
"""
|
"""
|
||||||
# TODO: Implement SSL pass-through handling and change conntype
|
# TODO: Implement SSL pass-through handling and change conntype
|
||||||
passthrough = [
|
passthrough = [
|
||||||
@ -160,7 +162,7 @@ class ConnectionHandler:
|
|||||||
]
|
]
|
||||||
if self.server_conn.address.host in passthrough or self.sni in passthrough:
|
if self.server_conn.address.host in passthrough or self.sni in passthrough:
|
||||||
self.conntype = "tcp"
|
self.conntype = "tcp"
|
||||||
return
|
raise ConnectionTypeChange
|
||||||
|
|
||||||
# Logging
|
# Logging
|
||||||
if client or server:
|
if client or server:
|
||||||
|
Loading…
Reference in New Issue
Block a user