Skip to content

Add 307 / 308 Redirect Status Code Support #3823

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion apis/v1/httproute_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -1224,7 +1224,7 @@ type HTTPRequestRedirectFilter struct {
//
// +optional
// +kubebuilder:default=302
// +kubebuilder:validation:Enum=301;302
// +kubebuilder:validation:Enum=301;302;307;308
StatusCode *int `json:"statusCode,omitempty"`
}

Expand Down

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 8 additions & 0 deletions config/crd/standard/gateway.networking.k8s.io_httproutes.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

24 changes: 24 additions & 0 deletions conformance/tests/httproute-redirect-host-and-status.go
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,30 @@ var HTTPRouteRedirectHostAndStatus = suite.ConformanceTest{
Host: "example.org",
},
Namespace: ns,
}, {
Request: http.Request{
Path: "/host-and-temporary",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 307,
},
RedirectRequest: &roundtripper.RedirectRequest{
Host: "example.org",
},
Namespace: ns,
}, {
Request: http.Request{
Path: "/host-and-permanent",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 308,
},
RedirectRequest: &roundtripper.RedirectRequest{
Host: "example.org",
},
Namespace: ns,
},
}
for i := range testCases {
Expand Down
19 changes: 18 additions & 1 deletion conformance/tests/httproute-redirect-host-and-status.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,21 @@ spec:
requestRedirect:
statusCode: 301
hostname: example.org

- matches:
- path:
type: PathPrefix
value: /host-and-temporary
filters:
- type: RequestRedirect
requestRedirect:
statusCode: 307
hostname: example.org
- matches:
- path:
type: PathPrefix
value: /host-and-permanent
filters:
- type: RequestRedirect
requestRedirect:
statusCode: 308
hostname: example.org
48 changes: 48 additions & 0 deletions conformance/tests/httproute-redirect-path.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,30 @@ var HTTPRouteRedirectPath = suite.ConformanceTest{
Path: "/replacement-prefix",
},
Namespace: ns,
}, {
Request: http.Request{
Path: "/path-and-temporary",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 307,
},
RedirectRequest: &roundtripper.RedirectRequest{
Path: "/replacement-prefix",
},
Namespace: ns,
}, {
Request: http.Request{
Path: "/path-and-permanent",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 308,
},
RedirectRequest: &roundtripper.RedirectRequest{
Path: "/replacement-prefix",
},
Namespace: ns,
}, {
Request: http.Request{
Path: "/full-path-and-host",
Expand All @@ -123,6 +147,30 @@ var HTTPRouteRedirectPath = suite.ConformanceTest{
Path: "/replacement-full",
},
Namespace: ns,
}, {
Request: http.Request{
Path: "/full-path-and-temporary",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 307,
},
RedirectRequest: &roundtripper.RedirectRequest{
Path: "/replacement-full",
},
Namespace: ns,
}, {
Request: http.Request{
Path: "/full-path-and-permanent",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 308,
},
RedirectRequest: &roundtripper.RedirectRequest{
Path: "/replacement-full",
},
Namespace: ns,
},
}
for i := range testCases {
Expand Down
44 changes: 44 additions & 0 deletions conformance/tests/httproute-redirect-path.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,28 @@ spec:
type: ReplacePrefixMatch
replacePrefixMatch: /replacement-prefix
statusCode: 301
- matches:
- path:
type: PathPrefix
value: /path-and-temporary
filters:
- type: RequestRedirect
requestRedirect:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /replacement-prefix
statusCode: 307
- matches:
- path:
type: PathPrefix
value: /path-and-permanent
filters:
- type: RequestRedirect
requestRedirect:
path:
type: ReplacePrefixMatch
replacePrefixMatch: /replacement-prefix
statusCode: 308
- matches:
- path:
type: PathPrefix
Expand All @@ -71,3 +93,25 @@ spec:
type: ReplaceFullPath
replaceFullPath: /replacement-full
statusCode: 301
- matches:
- path:
type: PathPrefix
value: /full-path-and-temporary
filters:
- type: RequestRedirect
requestRedirect:
path:
type: ReplaceFullPath
replaceFullPath: /replacement-full
statusCode: 307
- matches:
- path:
type: PathPrefix
value: /full-path-and-permanent
filters:
- type: RequestRedirect
requestRedirect:
path:
type: ReplaceFullPath
replaceFullPath: /replacement-full
statusCode: 308
26 changes: 26 additions & 0 deletions conformance/tests/httproute-redirect-port.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,32 @@ var HTTPRouteRedirectPort = suite.ConformanceTest{
Host: "example.org",
},
Namespace: ns,
}, {
Request: http.Request{
Path: "/port-and-temporary",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 307,
},
RedirectRequest: &roundtripper.RedirectRequest{
Port: "8083",
Host: "example.org",
},
Namespace: ns,
}, {
Request: http.Request{
Path: "/port-and-permanent",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 308,
},
RedirectRequest: &roundtripper.RedirectRequest{
Port: "8083",
Host: "example.org",
},
Namespace: ns,
},
}
for i := range testCases {
Expand Down
20 changes: 20 additions & 0 deletions conformance/tests/httproute-redirect-port.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -43,3 +43,23 @@ spec:
port: 8083
hostname: example.org
statusCode: 302
- matches:
- path:
type: PathPrefix
value: /port-and-temporary
filters:
- type: RequestRedirect
requestRedirect:
port: 8083
hostname: example.org
statusCode: 307
- matches:
- path:
type: PathPrefix
value: /port-and-permanent
filters:
- type: RequestRedirect
requestRedirect:
port: 8083
hostname: example.org
statusCode: 308
21 changes: 21 additions & 0 deletions conformance/tests/httproute-redirect-scheme.go
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,27 @@ var HTTPRouteRedirectScheme = suite.ConformanceTest{
Host: "example.org",
},
Namespace: ns,
}, {
Request: http.Request{
Path: "/scheme-and-temporary",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 307,
},
RedirectRequest: &roundtripper.RedirectRequest{
Scheme: "https",
Host: "example.org",
},
Namespace: ns,
}, {
Request: http.Request{
Path: "/scheme-and-permanent",
UnfollowRedirect: true,
},
Response: http.Response{
StatusCode: 308,
},
},
}
for i := range testCases {
Expand Down
18 changes: 18 additions & 0 deletions conformance/tests/httproute-redirect-scheme.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ spec:
requestRedirect:
scheme: "https"
statusCode: 301
- matches:
- path:
type: PathPrefix
value: /scheme-and-temporary
filters:
- type: RequestRedirect
requestRedirect:
scheme: "https"
statusCode: 307
- matches:
- path:
type: PathPrefix
Expand All @@ -43,4 +52,13 @@ spec:
scheme: "https"
statusCode: 302
hostname: example.org
- matches:
- path:
type: PathPrefix
value: /scheme-and-permanent
filters:
- type: RequestRedirect
requestRedirect:
scheme: "https"
statusCode: 308

Loading