1
0
mirror of https://github.com/thib8956/nginx-proxy synced 2025-07-01 06:15:45 +00:00

feat: customizable non get redirect code

This commit is contained in:
Nicolas Duchon
2024-12-08 20:04:50 +01:00
parent 8447a36046
commit 9fc7cec15c
6 changed files with 85 additions and 21 deletions

View 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}/'

View 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

View File

@ -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),
])