store resolved ip addresses, fixes #187

This commit is contained in:
Maximilian Hils 2013-12-12 02:11:22 +01:00
parent 5f6eca8856
commit 28a234e28b
3 changed files with 17 additions and 3 deletions

View File

@ -288,7 +288,9 @@ class Request(HTTPMsg):
(or None, if request didn't results SSL setup) (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) assert isinstance(headers, ODictCaseless)
self.client_conn = client_conn self.client_conn = client_conn
self.httpversion = httpversion self.httpversion = httpversion
@ -299,6 +301,7 @@ class Request(HTTPMsg):
self.close = False self.close = False
self.tcp_setup_timestamp = tcp_setup_timestamp self.tcp_setup_timestamp = tcp_setup_timestamp
self.ssl_setup_timestamp = ssl_setup_timestamp self.ssl_setup_timestamp = ssl_setup_timestamp
self.ip = ip
# Have this request's cookies been modified by sticky cookies or auth? # Have this request's cookies been modified by sticky cookies or auth?
self.stickycookie = False self.stickycookie = False
@ -364,6 +367,7 @@ class Request(HTTPMsg):
self.timestamp_end = state["timestamp_end"] self.timestamp_end = state["timestamp_end"]
self.tcp_setup_timestamp = state["tcp_setup_timestamp"] self.tcp_setup_timestamp = state["tcp_setup_timestamp"]
self.ssl_setup_timestamp = state["ssl_setup_timestamp"] self.ssl_setup_timestamp = state["ssl_setup_timestamp"]
self.ip = state["ip"]
def _get_state(self): def _get_state(self):
return dict( return dict(
@ -379,7 +383,8 @@ class Request(HTTPMsg):
timestamp_start = self.timestamp_start, timestamp_start = self.timestamp_start,
timestamp_end = self.timestamp_end, timestamp_end = self.timestamp_end,
tcp_setup_timestamp = self.tcp_setup_timestamp, 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 @classmethod
@ -397,7 +402,8 @@ class Request(HTTPMsg):
state["timestamp_start"], state["timestamp_start"],
state["timestamp_end"], state["timestamp_end"],
state["tcp_setup_timestamp"], state["tcp_setup_timestamp"],
state["ssl_setup_timestamp"] state["ssl_setup_timestamp"],
state["ip"]
) )
def __hash__(self): def __hash__(self):

View File

@ -231,6 +231,9 @@ class ProxyHandler(tcp.BaseHandler):
sc.rfile.reset_timestamps() sc.rfile.reset_timestamps()
try: try:
tsstart = utils.timestamp() tsstart = utils.timestamp()
peername = sc.connection.getpeername()
if peername:
request.ip = peername[0]
httpversion, code, msg, headers, content = http.read_response( httpversion, code, msg, headers, content = http.read_response(
sc.rfile, sc.rfile,
request.method, request.method,

View File

@ -289,6 +289,11 @@ class TestProxy(tservers.HTTPProxTest):
assert second_request.tcp_setup_timestamp == None assert second_request.tcp_setup_timestamp == None
assert second_request.ssl_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): class TestProxySSL(tservers.HTTPProxTest):
ssl=True ssl=True