Skip to content

Commit 9332f02

Browse files
authored
chore: remove host rewrite middleware (#10977)
Introduced in #1414 in 2016 Replaced in twine in pypa/twine#201 The DNS entry no longer resolves either. $ host upload.pypi.io Host upload.pypi.io not found: 3(NXDOMAIN) Signed-off-by: Mike Fiedler <[email protected]>
1 parent 9ab4b6d commit 9332f02

File tree

4 files changed

+2
-49
lines changed

4 files changed

+2
-49
lines changed

tests/unit/test_config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424

2525
from warehouse import config
2626
from warehouse.errors import BasicAuthBreachedPassword, BasicAuthFailedPassword
27-
from warehouse.utils.wsgi import HostRewrite, ProxyFixer, VhmRootRemover
27+
from warehouse.utils.wsgi import ProxyFixer, VhmRootRemover
2828

2929

3030
class TestRequireHTTPSTween:
@@ -301,7 +301,6 @@ def __init__(self):
301301
assert configurator_obj.add_wsgi_middleware.calls == [
302302
pretend.call(ProxyFixer, token="insecure token", num_proxies=1),
303303
pretend.call(VhmRootRemover),
304-
pretend.call(HostRewrite),
305304
]
306305
assert configurator_obj.include.calls == (
307306
[

tests/unit/utils/test_wsgi.py

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -162,29 +162,3 @@ def test_passes_through_headers(self):
162162

163163
assert resp is response
164164
assert app.calls == [pretend.call({"HTTP_X_FOOBAR": "wat"}, start_response)]
165-
166-
167-
class TestHostRewrite:
168-
def test_rewrites_host(self):
169-
response = pretend.stub()
170-
app = pretend.call_recorder(lambda e, s: response)
171-
environ = {"HTTP_HOST": "upload.pypi.io"}
172-
start_response = pretend.stub()
173-
174-
resp = wsgi.HostRewrite(app)(environ, start_response)
175-
176-
assert resp is response
177-
assert app.calls == [
178-
pretend.call({"HTTP_HOST": "upload.pypi.org"}, start_response)
179-
]
180-
181-
def test_ignores_other_hosts(self):
182-
response = pretend.stub()
183-
app = pretend.call_recorder(lambda e, s: response)
184-
environ = {"HTTP_HOST": "example.com"}
185-
start_response = pretend.stub()
186-
187-
resp = wsgi.HostRewrite(app)(environ, start_response)
188-
189-
assert resp is response
190-
assert app.calls == [pretend.call({"HTTP_HOST": "example.com"}, start_response)]

warehouse/config.py

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@
2626

2727
from warehouse.errors import BasicAuthBreachedPassword, BasicAuthFailedPassword
2828
from warehouse.utils.static import ManifestCacheBuster
29-
from warehouse.utils.wsgi import HostRewrite, ProxyFixer, VhmRootRemover
29+
from warehouse.utils.wsgi import ProxyFixer, VhmRootRemover
3030

3131

3232
class Environment(enum.Enum):
@@ -568,10 +568,6 @@ def configure(settings=None):
568568
# Protect against cache poisoning via the X-Vhm-Root headers.
569569
config.add_wsgi_middleware(VhmRootRemover)
570570

571-
# Fix our host header when getting sent upload.pypi.io as a HOST.
572-
# TODO: Remove this, this is at the wrong layer.
573-
config.add_wsgi_middleware(HostRewrite)
574-
575571
# We want Sentry to be the last things we add here so that it's the outer
576572
# most WSGI middleware.
577573
config.include(".sentry")

warehouse/utils/wsgi.py

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -81,19 +81,3 @@ def __call__(self, environ, start_response):
8181
del environ["HTTP_X_VHM_ROOT"]
8282

8383
return self.app(environ, start_response)
84-
85-
86-
class HostRewrite:
87-
88-
# TODO: This entire class should not be required.
89-
90-
def __init__(self, app):
91-
self.app = app
92-
93-
def __call__(self, environ, start_response):
94-
# If the host header matches upload.pypi.io, then we want to rewrite it
95-
# so that it is instead upload.pypi.org.
96-
if environ.get("HTTP_HOST", "").lower() == "upload.pypi.io":
97-
environ["HTTP_HOST"] = "upload.pypi.org"
98-
99-
return self.app(environ, start_response)

0 commit comments

Comments
 (0)