mirror of
https://github.com/thib8956/nginx-proxy
synced 2025-07-01 14:25:46 +00:00
feat: customizable non get redirect code
This commit is contained in:
38
test/test_ssl/test_redirect_custom.py
Normal file
38
test/test_ssl/test_redirect_custom.py
Normal file
@ -0,0 +1,38 @@
|
||||
import pytest
|
||||
|
||||
|
||||
@pytest.mark.parametrize("host,http_method,expected_code", [
|
||||
("nginx-proxy.tld", "GET", 301),
|
||||
("nginx-proxy.tld", "HEAD", 301),
|
||||
("nginx-proxy.tld", "POST", 308),
|
||||
("nginx-proxy.tld", "PUT", 308),
|
||||
("nginx-proxy.tld", "PATCH", 308),
|
||||
("nginx-proxy.tld", "DELETE", 308),
|
||||
("nginx-proxy.tld", "OPTIONS", 308),
|
||||
("nginx-proxy.tld", "CONNECT", 405),
|
||||
("nginx-proxy.tld", "TRACE", 405),
|
||||
("web2.nginx-proxy.tld", "GET", 301),
|
||||
("web2.nginx-proxy.tld", "HEAD", 301),
|
||||
("web2.nginx-proxy.tld", "POST", 307),
|
||||
("web2.nginx-proxy.tld", "PUT", 307),
|
||||
("web2.nginx-proxy.tld", "PATCH", 307),
|
||||
("web2.nginx-proxy.tld", "DELETE", 307),
|
||||
("web2.nginx-proxy.tld", "OPTIONS", 307),
|
||||
("web2.nginx-proxy.tld", "CONNECT", 405),
|
||||
("web2.nginx-proxy.tld", "TRACE", 405),
|
||||
])
|
||||
def test_custom_redirect_by_method(
|
||||
docker_compose,
|
||||
nginxproxy,
|
||||
host: str,
|
||||
http_method: str,
|
||||
expected_code: int,
|
||||
):
|
||||
r = nginxproxy.request(
|
||||
method=http_method,
|
||||
url=f'http://{host}',
|
||||
allow_redirects=False,
|
||||
)
|
||||
assert r.status_code == expected_code
|
||||
if expected_code in { 301, 302, 307, 308 }:
|
||||
assert r.headers['Location'] == f'https://{host}/'
|
26
test/test_ssl/test_redirect_custom.yml
Normal file
26
test/test_ssl/test_redirect_custom.yml
Normal file
@ -0,0 +1,26 @@
|
||||
services:
|
||||
web1:
|
||||
image: web
|
||||
expose:
|
||||
- "81"
|
||||
environment:
|
||||
WEB_PORTS: "81"
|
||||
VIRTUAL_HOST: "nginx-proxy.tld"
|
||||
|
||||
web2:
|
||||
image: web
|
||||
expose:
|
||||
- "82"
|
||||
environment:
|
||||
WEB_PORTS: "82"
|
||||
VIRTUAL_HOST: "web2.nginx-proxy.tld"
|
||||
labels:
|
||||
com.github.nginx-proxy.nginx-proxy.non-get-redirect: 307
|
||||
|
||||
sut:
|
||||
image: nginxproxy/nginx-proxy:test
|
||||
environment:
|
||||
NON_GET_REDIRECT: 308
|
||||
volumes:
|
||||
- /var/run/docker.sock:/tmp/docker.sock:ro
|
||||
- ./certs:/etc/nginx/certs:ro
|
@ -3,12 +3,12 @@ import pytest
|
||||
|
||||
@pytest.mark.parametrize("http_method,expected_code", [
|
||||
("GET", 301),
|
||||
("HEAD", 308),
|
||||
("POST", 308),
|
||||
("PUT", 308),
|
||||
("PATCH", 308),
|
||||
("DELETE", 308),
|
||||
("OPTIONS", 308),
|
||||
("HEAD", 301),
|
||||
("POST", 301),
|
||||
("PUT", 301),
|
||||
("PATCH", 301),
|
||||
("DELETE", 301),
|
||||
("OPTIONS", 301),
|
||||
("CONNECT", 405),
|
||||
("TRACE", 405),
|
||||
])
|
Reference in New Issue
Block a user