Skip to content
Closed
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
5 changes: 1 addition & 4 deletions proxy/common/types.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,7 @@
else:
from typing_extensions import Protocol

if TYPE_CHECKING:
DictQueueType = queue.Queue[Dict[str, Any]] # pragma: no cover
else:
DictQueueType = queue.Queue
DictQueueType = queue.Queue[Dict[str, Any]] if TYPE_CHECKING else queue.Queue


class HasFileno(Protocol):
Expand Down
6 changes: 1 addition & 5 deletions proxy/core/event/dispatcher.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,11 +84,7 @@ def run(self) -> None:
self.run_once()
except queue.Empty:
pass
except BrokenPipeError:
pass
except EOFError:
pass
except KeyboardInterrupt:
except (BrokenPipeError, EOFError, KeyboardInterrupt):
pass
except Exception as e:
logger.exception('Event dispatcher exception', exc_info=e)
5 changes: 1 addition & 4 deletions proxy/core/event/subscriber.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,11 +61,8 @@ def unsubscribe(self) -> None:

try:
self.event_queue.unsubscribe(self.relay_sub_id)
except BrokenPipeError:
except (BrokenPipeError, EOFError):
pass
except EOFError:
pass

self.relay_shutdown.set()
self.relay_thread.join()
logger.debug(
Expand Down
13 changes: 3 additions & 10 deletions proxy/plugin/filter_by_url_regex.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 +59,8 @@ def handle_client_request(
request_host = None
if request.host:
request_host = request.host
else:
if b'host' in request.headers:
request_host = request.header(b'host')
elif b'host' in request.headers:
request_host = request.header(b'host')

if not request_host:
logger.error("Cannot determine host")
Expand All @@ -72,9 +71,7 @@ def handle_client_request(
request_host,
request.path,
)
# check URL against list
rule_number = 1
for blocked_entry in self.filters:
for rule_number, blocked_entry in enumerate(self.filters, start=1):
# if regex matches on URL
if re.search(text_(blocked_entry['regex']), text_(url)):
# log that the request has been filtered
Expand All @@ -92,10 +89,6 @@ def handle_client_request(
headers={b'Connection': b'close'},
reason=b'Blocked',
)
# stop looping through filter list
break
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This removes unreachable code. Could you also try dropping the linter exclusions at https://github.com/abhinavsingh/proxy.py/blob/7c5877b/.pylintrc#L129 and https://github.com/abhinavsingh/proxy.py/blob/7c5877b/.flake8#L149 to see if this was the only place with this type of a linting violation?

# increment rule number
rule_number += 1
return request

def handle_upstream_chunk(self, chunk: memoryview) -> memoryview:
Expand Down
2 changes: 1 addition & 1 deletion proxy/plugin/reverse_proxy.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def handle_request(self, request: HttpParser) -> None:
upstream = random.choice(ReverseProxyPlugin.REVERSE_PROXY_PASS)
url = urlparse.urlsplit(upstream)
assert url.hostname
with socket_connection((text_(url.hostname), url.port if url.port else DEFAULT_HTTP_PORT)) as conn:
with socket_connection((text_(url.hostname), url.port or DEFAULT_HTTP_PORT)) as conn:
conn.send(request.build())
self.client.queue(memoryview(conn.recv(DEFAULT_BUFFER_SIZE)))

Expand Down