Skip to content

Commit

Permalink
fix: do not propagate well-known port number for xds portRedirect (en…
Browse files Browse the repository at this point in the history
…voyproxy#3628)

* do not propagate well-known port number in xds translator for portRedirect

Signed-off-by: shawnh2 <[email protected]>

* fix yaml lint

Signed-off-by: shawnh2 <[email protected]>

---------

Signed-off-by: shawnh2 <[email protected]>
Signed-off-by: “bjlhlin” <“[email protected]”>
Signed-off-by: bjlhlin <[email protected]>
  • Loading branch information
shawnh2 authored and bjlhlin committed Jun 24, 2024
1 parent 65a727e commit fe7bcb2
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 1 deletion.
4 changes: 3 additions & 1 deletion internal/xds/translator/route.go
Original file line number Diff line number Diff line change
Expand Up @@ -345,7 +345,9 @@ func buildXdsRedirectAction(httpRoute *ir.HTTPRoute) *routev3.RedirectAction {
if redirection.Hostname != nil {
routeAction.HostRedirect = *redirection.Hostname
}
if redirection.Port != nil {
// Ignore the redirect port if it is a well-known port number, in order to
// prevent the port be added in the response's location header.
if redirection.Port != nil && *redirection.Port != 80 && *redirection.Port != 443 {
routeAction.PortRedirect = *redirection.Port
}
if redirection.StatusCode != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,3 +50,32 @@ http:
redirect:
path:
prefixMatchReplace: /
- name: "redirect-route-4"
hostname: "*"
destination:
name: "redirect-route-dest"
settings:
- endpoints:
- host: "1.2.3.4"
port: 50000
redirect:
scheme: https
statusCode: 302
hostname: "redirected.com"
path:
prefixMatchReplace: /redirected
- name: "redirect-route-5"
hostname: "*"
destination:
name: "redirect-route-dest"
settings:
- endpoints:
- host: "1.2.3.4"
port: 50000
redirect:
scheme: https
statusCode: 302
port: 443
hostname: "redirected.com"
path:
prefixMatchReplace: /redirected
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,19 @@
pattern:
regex: ^/redirect/\/*
substitution: /
- match:
prefix: /
name: redirect-route-4
redirect:
hostRedirect: redirected.com
prefixRewrite: /redirected
responseCode: FOUND
schemeRedirect: https
- match:
prefix: /
name: redirect-route-5
redirect:
hostRedirect: redirected.com
prefixRewrite: /redirected
responseCode: FOUND
schemeRedirect: https

0 comments on commit fe7bcb2

Please sign in to comment.