mirror of
https://github.com/Grasscutters/mitmproxy.git
synced 2024-11-23 08:11:00 +00:00
store resolved ip addresses, fixes #187
This commit is contained in:
parent
5f6eca8856
commit
28a234e28b
@ -288,7 +288,9 @@ class Request(HTTPMsg):
|
||||
(or None, if request didn't results SSL setup)
|
||||
|
||||
"""
|
||||
def __init__(self, client_conn, httpversion, host, port, scheme, method, path, headers, content, timestamp_start=None, timestamp_end=None, tcp_setup_timestamp=None, ssl_setup_timestamp=None):
|
||||
def __init__(
|
||||
self, client_conn, httpversion, host, port, scheme, method, path, headers, content, timestamp_start=None,
|
||||
timestamp_end=None, tcp_setup_timestamp=None, ssl_setup_timestamp=None, ip=None):
|
||||
assert isinstance(headers, ODictCaseless)
|
||||
self.client_conn = client_conn
|
||||
self.httpversion = httpversion
|
||||
@ -299,6 +301,7 @@ class Request(HTTPMsg):
|
||||
self.close = False
|
||||
self.tcp_setup_timestamp = tcp_setup_timestamp
|
||||
self.ssl_setup_timestamp = ssl_setup_timestamp
|
||||
self.ip = ip
|
||||
|
||||
# Have this request's cookies been modified by sticky cookies or auth?
|
||||
self.stickycookie = False
|
||||
@ -364,6 +367,7 @@ class Request(HTTPMsg):
|
||||
self.timestamp_end = state["timestamp_end"]
|
||||
self.tcp_setup_timestamp = state["tcp_setup_timestamp"]
|
||||
self.ssl_setup_timestamp = state["ssl_setup_timestamp"]
|
||||
self.ip = state["ip"]
|
||||
|
||||
def _get_state(self):
|
||||
return dict(
|
||||
@ -379,7 +383,8 @@ class Request(HTTPMsg):
|
||||
timestamp_start = self.timestamp_start,
|
||||
timestamp_end = self.timestamp_end,
|
||||
tcp_setup_timestamp = self.tcp_setup_timestamp,
|
||||
ssl_setup_timestamp = self.ssl_setup_timestamp
|
||||
ssl_setup_timestamp = self.ssl_setup_timestamp,
|
||||
ip = self.ip
|
||||
)
|
||||
|
||||
@classmethod
|
||||
@ -397,7 +402,8 @@ class Request(HTTPMsg):
|
||||
state["timestamp_start"],
|
||||
state["timestamp_end"],
|
||||
state["tcp_setup_timestamp"],
|
||||
state["ssl_setup_timestamp"]
|
||||
state["ssl_setup_timestamp"],
|
||||
state["ip"]
|
||||
)
|
||||
|
||||
def __hash__(self):
|
||||
|
@ -231,6 +231,9 @@ class ProxyHandler(tcp.BaseHandler):
|
||||
sc.rfile.reset_timestamps()
|
||||
try:
|
||||
tsstart = utils.timestamp()
|
||||
peername = sc.connection.getpeername()
|
||||
if peername:
|
||||
request.ip = peername[0]
|
||||
httpversion, code, msg, headers, content = http.read_response(
|
||||
sc.rfile,
|
||||
request.method,
|
||||
|
@ -289,6 +289,11 @@ class TestProxy(tservers.HTTPProxTest):
|
||||
assert second_request.tcp_setup_timestamp == None
|
||||
assert second_request.ssl_setup_timestamp == None
|
||||
|
||||
def test_request_ip(self):
|
||||
f = self.pathod("200:b@100")
|
||||
assert f.status_code == 200
|
||||
request = self.master.state.view[0].request
|
||||
assert request.ip == "127.0.0.1"
|
||||
|
||||
class TestProxySSL(tservers.HTTPProxTest):
|
||||
ssl=True
|
||||
|
Loading…
Reference in New Issue
Block a user