Skip to content

Commit 4fb88af

Browse files
authored
Merge pull request #62 from immerrr/fix-redirect-location-scheme-for-secure-server
httpbin_secure: fix redirect Location to have "https://" scheme
2 parents be3c320 + 83f637d commit 4fb88af

File tree

2 files changed

+12
-0
lines changed

2 files changed

+12
-0
lines changed

pytest_httpbin/serve.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -69,6 +69,7 @@ def finish_request(self, request, client_address):
6969
server_side=True,
7070
suppress_ragged_eofs=False,
7171
)
72+
self.base_environ['HTTPS'] = 'yes'
7273
self.RequestHandlerClass(ssock, client_address, self)
7374
except Exception as e:
7475
print("pytest-httpbin server hit an exception serving request: %s" % e)

tests/test_server.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,14 @@ def test_fixed_port_environment_variables(protocol):
9292
del os.environ[envvar]
9393
else:
9494
os.environ[envvar] = envvar_original
95+
96+
97+
def test_redirect_location_is_https_for_secure_server(httpbin_secure):
98+
assert httpbin_secure.url.startswith('https://')
99+
response = requests.get(
100+
httpbin_secure + "/redirect-to?url=/html",
101+
allow_redirects=False
102+
)
103+
assert response.status_code == 302
104+
assert response.headers.get('Location')
105+
assert response.headers['Location'].startswith('https://')

0 commit comments

Comments
 (0)