Skip to content
Merged
Show file tree
Hide file tree
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
6 changes: 3 additions & 3 deletions helper/chrome_with_proxy.sh
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,6 @@ fi
--no-first-run \
--no-default-browser-check \
--user-data-dir="$(mktemp -d -t 'chrome-remote_data_dir')" \
--proxy-server=${PROXY_PY_ADDR} \
--ignore-urlfetcher-cert-requests \
--ignore-certificate-errors
--proxy-server=${PROXY_PY_ADDR} #\
# --ignore-urlfetcher-cert-requests \
# --ignore-certificate-errors
8 changes: 4 additions & 4 deletions proxy/http/handler.py
Original file line number Diff line number Diff line change
Expand Up @@ -288,13 +288,13 @@ def handle_writables(self, writables: List[Union[int, HasFileno]]) -> bool:

try:
self.client.flush()
except OSError:
logger.error('OSError when flushing buffer to client')
return True
except BrokenPipeError:
logger.error(
'BrokenPipeError when flushing buffer for client')
return True
except OSError:
logger.error('OSError when flushing buffer to client')
return True
return False

def handle_readables(self, readables: List[Union[int, HasFileno]]) -> bool:
Expand Down Expand Up @@ -359,7 +359,7 @@ def handle_readables(self, readables: List[Union[int, HasFileno]]) -> bool:
except HttpProtocolException as e:
logger.debug(
'HttpProtocolException type raised')
response = e.response(self.request)
response: Optional[memoryview] = e.response(self.request)
if response:
self.client.queue(response)
return True
Expand Down
5 changes: 5 additions & 0 deletions proxy/http/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,8 @@ def is_http_1_1_keep_alive(self) -> bool:
return self.version == HTTP_1_1 and \
(not self.has_header(b'Connection') or
self.header(b'Connection').lower() == b'keep-alive')

def is_connection_upgrade(self) -> bool:
return self.version == HTTP_1_1 and \
self.has_header(b'Connection') and \
self.has_header(b'Upgrade')
12 changes: 11 additions & 1 deletion proxy/http/proxy/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,15 @@ def on_client_data(self, raw: memoryview) -> Optional[memoryview]:
if self.request.state == httpParserStates.COMPLETE and (
self.request.method != httpMethods.CONNECT or
self.flags.tls_interception_enabled()):

if self.pipeline_request is not None and \
self.pipeline_request.is_connection_upgrade():
# Previous pipelined request was a WebSocket
# upgrade request. Incoming client data now
# must be treated as WebSocket protocol packets.
self.server.queue(raw)
return None

if self.pipeline_request is None:
self.pipeline_request = HttpParser(
httpParserTypes.REQUEST_PARSER)
Expand All @@ -226,7 +235,8 @@ def on_client_data(self, raw: memoryview) -> Optional[memoryview]:
self.server.queue(
memoryview(
self.pipeline_request.build()))
self.pipeline_request = None
if not self.pipeline_request.is_connection_upgrade():
self.pipeline_request = None
else:
self.server.queue(raw)
return None
Expand Down
2 changes: 1 addition & 1 deletion proxy/http/websocket.py
Original file line number Diff line number Diff line change
Expand Up @@ -231,7 +231,7 @@ def run_once(self) -> bool:
self.selector.register(self.sock.fileno(), ev)
events = self.selector.select(timeout=1)
self.selector.unregister(self.sock)
for key, mask in events:
for _, mask in events:
if mask & selectors.EVENT_READ and self.on_message:
raw = self.recv()
if raw is None or raw.tobytes() == b'':
Expand Down