Skip to content

Commit

Permalink
remove redirect filter header modification
Browse files Browse the repository at this point in the history
  • Loading branch information
salonichf5 committed Sep 6, 2024
1 parent 8f35ab7 commit b1cdb27
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 74 deletions.
2 changes: 1 addition & 1 deletion charts/nginx-gateway-fabric/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -103,7 +103,7 @@ nginx:
# type: "cidr",
# }
# ]
# setIPRecursively: true
# setIPRecursively: true
# telemetry:
# exporter:
# endpoint: otel-collector.default.svc:4317
Expand Down
34 changes: 8 additions & 26 deletions internal/mode/static/nginx/config/servers.go
Original file line number Diff line number Diff line change
Expand Up @@ -800,7 +800,14 @@ func generateProxySetHeaders(filters *dataplane.HTTPFilters, grpc bool) []http.H
copy(headers, grpcBaseHeaders)
}

setHeaderForHTTPSRedirect(filters, headers)
if filters != nil && filters.RequestURLRewrite != nil && filters.RequestURLRewrite.Hostname != nil {
for i, header := range headers {
if header.Name == "Host" {
headers[i].Value = *filters.RequestURLRewrite.Hostname
break
}
}
}

if filters == nil || filters.RequestHeaderModifiers == nil {
return headers
Expand Down Expand Up @@ -829,31 +836,6 @@ func generateProxySetHeaders(filters *dataplane.HTTPFilters, grpc bool) []http.H
return append(proxySetHeaders, headers...)
}

func setHeaderForHTTPSRedirect(filters *dataplane.HTTPFilters, headers []http.Header) {
if filters == nil {
return
}

if filters.RequestURLRewrite != nil && filters.RequestURLRewrite.Hostname != nil {
for i, header := range headers {
if header.Name == "Host" {
headers[i].Value = *filters.RequestURLRewrite.Hostname
break
}
}
}
if filters.RequestRedirect != nil &&
filters.RequestRedirect.Scheme != nil &&
*filters.RequestRedirect.Scheme == http.HTTPSScheme {
for i, header := range headers {
if header.Name == "X-Forwarded-Proto" {
headers[i].Value = http.HTTPSScheme
return
}
}
}
}

func generateResponseHeaders(filters *dataplane.HTTPFilters) http.ResponseHeaders {
if filters == nil || filters.ResponseHeaderModifiers == nil {
return http.ResponseHeaders{}
Expand Down
47 changes: 0 additions & 47 deletions internal/mode/static/nginx/config/servers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2681,53 +2681,6 @@ func TestGenerateProxySetHeaders(t *testing.T) {
},
},
},
{
msg: "request redirect filter with https scheme",
filters: &dataplane.HTTPFilters{
RequestRedirect: &dataplane.HTTPRequestRedirectFilter{
Scheme: helpers.GetPointer("https"),
},
},
expectedHeaders: []http.Header{
{
Name: "Host",
Value: "$gw_api_compliant_host",
},
{
Name: "X-Forwarded-For",
Value: "$proxy_add_x_forwarded_for",
},
{
Name: "Upgrade",
Value: "$http_upgrade",
},
{
Name: "Connection",
Value: "$connection_upgrade",
},
{
Name: "X-Real-IP",
Value: "$remote_addr",
},
{
Name: "X-Forwarded-Proto",
Value: "https",
},
{
Name: "X-Forwarded-Host",
Value: "$host",
},
{
Name: "X-Forwarded-Port",
Value: "$server_port",
},
},
},
{
msg: "no filter set",
expectedHeaders: httpBaseHeaders,
GRPC: false,
},
}

for _, tc := range tests {
Expand Down

0 comments on commit b1cdb27

Please sign in to comment.