Skip to content

Commit

Permalink
cleanup comments
Browse files Browse the repository at this point in the history
  • Loading branch information
bluet committed May 3, 2020
1 parent 1feda62 commit 58fe9d8
Showing 1 changed file with 4 additions and 33 deletions.
37 changes: 4 additions & 33 deletions proxybroker/server.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import asyncio
import heapq
import time
from pprint import pprint
# from pprint import pprint

from .errors import (
BadResponseError,
Expand Down Expand Up @@ -199,10 +199,6 @@ async def _handle(self, client_reader, client_writer):
'Accepted connection from %s'
% (client_writer.get_extra_info('peername'),)
)
pprint(
'Accepted connection from %s'
% (client_writer.get_extra_info('peername'),)
)

request, headers = await self._parse_request(client_reader)
scheme = self._identify_scheme(headers)
Expand All @@ -211,10 +207,6 @@ async def _handle(self, client_reader, client_writer):
'client: %d; request: %s; headers: %s; scheme: %s'
% (client, request, headers, scheme)
)
pprint(
'client: %d; request: %s; headers: %s; scheme: %s'
% (client, request, headers, scheme)
)

if headers['Host'] == 'proxyremove':
host, port = headers['Path'].split('/')[3].split(':')
Expand All @@ -235,10 +227,7 @@ async def _handle(self, client_reader, client_writer):
'client: %d; attempt: %d; proxy: %s; proto: %s'
% (client, attempt, proxy, proto)
)
pprint(
'client: %d; attempt: %d; proxy: %s; proto: %s'
% (client, attempt, proxy, proto)
)

try:
await proxy.connect()

Expand All @@ -259,15 +248,12 @@ async def _handle(self, client_reader, client_writer):
else: # proto: HTTP & HTTPS
await proxy.send(request)

pprint('Proxy Picked:')
pprint(proxy)
inject_resp_header = {
'headers': {
'X-Proxy-Info': proxy.host + ':' + str(proxy.port)
}
}

pprint('Connecting IO Stream')
stime = time.time()
stream = [
asyncio.ensure_future(
Expand Down Expand Up @@ -353,34 +339,23 @@ def _choice_proto(self, proxy, scheme):

async def _stream(self, reader, writer, length=65536, scheme=None, inject=None):
checked = False
pprint('_stream inject:')
pprint(inject)

try:
while not reader.at_eof():
pprint('_stream not eof')
data = await asyncio.wait_for(
reader.read(length), self._timeout
)
# pprint(data)
if not data:
pprint('no data')
writer.close()
break
elif scheme and not checked:
pprint('check status')
self._check_response(data, scheme)
pprint('status checked')

pprint(inject.get('headers'))
pprint(str(len(inject['headers'])))
if inject.get('headers') != None and len(inject['headers']) > 0:
pprint('going to inject headers')
data = self._inject_headers(data, scheme, inject['headers'])

checked = True

pprint('SOME DATA')


writer.write(data)
await writer.drain()

Expand Down Expand Up @@ -409,10 +384,6 @@ def _check_response(self, data, scheme):

def _inject_headers(self, data, scheme, headers):
custom_lines = []
pprint('in _inject_headers:')
pprint(scheme)
pprint(headers)
pprint(data)

if scheme == 'HTTP' or scheme == 'HTTPS':
status_line, rest_lines = data.split(b'\r\n', 1)
Expand Down

0 comments on commit 58fe9d8

Please sign in to comment.