Skip to content

Added request and response logging for debugging reasons #1

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 8 commits into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class HttpParser(object):
def __init__(self, type=None):
self.state = HTTP_PARSER_STATE_INITIALIZED
self.type = type if type else HTTP_REQUEST_PARSER

self.raw = ''
self.buffer = ''

Expand Down Expand Up @@ -125,7 +125,9 @@ def process(self, data):
if self.chunker.state == CHUNK_PARSER_STATE_COMPLETE:
self.body = self.chunker.body
self.state = HTTP_PARSER_STATE_COMPLETE


logging.info("RESPONSE >>")
logging.info("Response Headers: %s \n Response Body: %s" % (self.headers, self.body))
return False, ''

line, data = HttpParser.split(data)
Expand Down Expand Up @@ -299,7 +301,7 @@ def __init__(self, client):

self.request = HttpParser()
self.response = HttpParser(HTTP_RESPONSE_PARSER)

self.connection_established_pkt = CRLF.join([
'HTTP/1.1 200 Connection established',
'Proxy-agent: proxy.py v%s' % __version__,
Expand All @@ -326,7 +328,7 @@ def _process_request(self, data):

# parse http request
self.request.parse(data)

# once http request parser has reached the state complete
# we attempt to establish connection to destination server
if self.request.state == HTTP_PARSER_STATE_COMPLETE:
Expand Down Expand Up @@ -358,6 +360,10 @@ def _process_request(self, data):
del_headers=['proxy-connection', 'connection', 'keep-alive'],
add_headers=[('Connection', 'Close')]
))
logging.info("REQUESTS >>")
logging.info("REQUEST METHOD: %s at %s" % (self.request.method, self.request.url))
logging.info("REQUEST HEADERS: %s\n" % self.request.headers)
logging.info("REQUEST BODY: %s \n" % self.request.body)

def _process_response(self, data):
# parse incoming response packet
Expand Down