Skip to content

Commit d502349

Browse files
authored
Avoid closing upstream if its managed by plugins (#1518)
* Avoid closing upstream if its managed by plugins * Anchor not found due to Sphinx/Github compatibility * Use macos-latest * Just node 12.x. 10 and 11 are too old * node 20.x
1 parent ad2e107 commit d502349

File tree

4 files changed

+15
-16
lines changed

4 files changed

+15
-16
lines changed

.github/workflows/test-library.yml

+5-5
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ jobs:
439439
# max-parallel: 4
440440
matrix:
441441
os:
442-
- macOS-12
442+
- macOS-latest
443443
- Ubuntu-24.04
444444
- Windows-latest
445445
python:
@@ -697,8 +697,8 @@ jobs:
697697
name: 📊 Node ${{ matrix.node }} @ ${{ matrix.os }}
698698
strategy:
699699
matrix:
700-
os: [ubuntu-24.04, windows-latest, macOS-12]
701-
node: ['10.x', '11.x', '12.x']
700+
os: [ubuntu-24.04, windows-latest, macOS-latest]
701+
node: ['20.x']
702702
# max-parallel: 4
703703
fail-fast: false
704704
steps:
@@ -725,7 +725,7 @@ jobs:
725725
726726
developer:
727727
runs-on: ${{ matrix.os }}
728-
name: 🧑‍💻 👩‍💻 👨‍💻 Developer setup ${{ matrix.node }} @ ${{ matrix.os }}
728+
name: 🧑‍💻 👩‍💻 👨‍💻 Developer setup ${{ matrix.python }} @ ${{ matrix.os }}
729729
strategy:
730730
matrix:
731731
os: [ubuntu-24.04, macOS-latest]
@@ -1049,7 +1049,7 @@ jobs:
10491049
uses: pypa/gh-action-pypi-publish@release/v1
10501050
with:
10511051
password: ${{ secrets.TESTPYPI_API_TOKEN }}
1052-
repository_url: https://test.pypi.org/legacy/
1052+
repository-url: https://test.pypi.org/legacy/
10531053
10541054
post-release-repo-update:
10551055
name: >-

CONTRIBUTING.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ This document describes how contributors can participate and iterate quickly whi
1111

1212
Contributors must start `proxy.py` from source to verify and develop new features / fixes. See `Run proxy.py from command line using repo source` in README.md for usage instructions.
1313

14-
[![WARNING](https://img.shields.io/static/v1?label=MacOS&message=warning&color=red)](https://github.com/abhinavsingh/proxy.py/issues/642#issuecomment-960819271) On `macOS` you must install `Python` using `pyenv`, as `Python` installed via `homebrew` tends to be problematic. See linked thread for more details.
14+
[![WARNING](https://img.shields.io/static/v1?label=MacOS&message=warning&color=red)](https://github.com/abhinavsingh/proxy.py/issues/642) On `macOS` you must install `Python` using `pyenv`, as `Python` installed via `homebrew` tends to be problematic. See linked thread for more details.
1515

1616
### Setup Git Hooks
1717

README.md

+3-3
Original file line numberDiff line numberDiff line change
@@ -1004,7 +1004,7 @@ Start `proxy.py` as:
10041004

10051005
`HttpProxyBasePlugin.resolve_dns` callback can also be used to configure `network interface` which must be used as the `source_address` for connection to the upstream server.
10061006

1007-
See [this thread](https://github.com/abhinavsingh/proxy.py/issues/535#issuecomment-961510862)
1007+
See [this thread](https://github.com/abhinavsingh/proxy.py/issues/535)
10081008
for more details.
10091009

10101010
PS: There is no plugin named, but [CustomDnsResolverPlugin](#customdnsresolverplugin)
@@ -2350,7 +2350,7 @@ Most likely it's a browser integration issue with system keychain.
23502350

23512351
`curl -v -x username:password@localhost:8899 https://httpbin.org/get`
23522352

2353-
- See [this thread](https://github.com/abhinavsingh/proxy.py/issues/89#issuecomment-534845710)
2353+
- See [this thread](https://github.com/abhinavsingh/proxy.py/issues/89)
23542354
for further details.
23552355

23562356
## Docker image not working on macOS
@@ -2559,7 +2559,7 @@ Contributors must start `proxy.py` from source to verify and develop new feature
25592559
See [Run proxy.py from command line using repo source](#from-command-line-using-repo-source) for details.
25602560

25612561

2562-
[![WARNING](https://img.shields.io/static/v1?label=MacOS&message=warning&color=red)](https://github.com/abhinavsingh/proxy.py/issues/642#issuecomment-960819271) On `macOS`
2562+
[![WARNING](https://img.shields.io/static/v1?label=MacOS&message=warning&color=red)](https://github.com/abhinavsingh/proxy.py/issues/642) On `macOS`
25632563
you must install `Python` using `pyenv`, as `Python` installed via `homebrew` tends
25642564
to be problematic. See linked thread for more details.
25652565

proxy/http/server/reverse.py

+6-7
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@ def __init__(self, *args: Any, **kwargs: Any):
4646
)
4747
self.plugins.append(plugin)
4848
self._upstream_proxy_pass: Optional[str] = None
49+
self._needs_upstream: bool = False
4950

5051
def do_upgrade(self, request: HttpParser) -> bool:
5152
"""Signal web protocol handler to not upgrade websocket requests by default."""
@@ -72,8 +73,6 @@ def handle_request(self, request: HttpParser) -> None:
7273
raise HttpProtocolException('before_routing closed connection')
7374
request = r
7475

75-
needs_upstream = False
76-
7776
# routes
7877
for plugin in self.plugins:
7978
for route in plugin.routes():
@@ -84,7 +83,7 @@ def handle_request(self, request: HttpParser) -> None:
8483
self.choice = Url.from_bytes(
8584
random.choice(route[1]),
8685
)
87-
needs_upstream = True
86+
self._needs_upstream = True
8887
break
8988
# Dynamic routes
9089
elif isinstance(route, str):
@@ -93,7 +92,7 @@ def handle_request(self, request: HttpParser) -> None:
9392
choice = plugin.handle_route(request, pattern)
9493
if isinstance(choice, Url):
9594
self.choice = choice
96-
needs_upstream = True
95+
self._needs_upstream = True
9796
self._upstream_proxy_pass = str(self.choice)
9897
elif isinstance(choice, memoryview):
9998
self.client.queue(choice)
@@ -107,7 +106,7 @@ def handle_request(self, request: HttpParser) -> None:
107106
else:
108107
raise ValueError('Invalid route')
109108

110-
if needs_upstream:
109+
if self._needs_upstream:
111110
assert self.choice and self.choice.hostname
112111
port = (
113112
self.choice.port or DEFAULT_HTTP_PORT
@@ -150,10 +149,10 @@ def handle_request(self, request: HttpParser) -> None:
150149
)
151150

152151
def on_client_connection_close(self) -> None:
153-
if self.upstream and not self.upstream.closed:
152+
if self._needs_upstream and self.upstream and not self.upstream.closed:
154153
logger.debug('Closing upstream server connection')
155154
self.upstream.close()
156-
self.upstream = None
155+
self.upstream = None
157156

158157
def on_client_data(
159158
self,

0 commit comments

Comments
 (0)