Skip to content
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

Set proxy host header to the exact value of the request host header #827

Merged
merged 1 commit into from
Jul 7, 2023
Merged
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
9 changes: 9 additions & 0 deletions internal/nginx/config/maps_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,13 @@ map {{ $m.Source }} {{ $m.Variable }} {
{{ end }}
}
{{- end }}

# Set $gw_api_compliant_host variable to the value of $http_host unless $http_host is empty, then set it to the value
# of $host. We prefer $http_host because it contains the original value of the host header, which is required by the
# Gateway API. However, in an HTTP/1.0 request, it's possible that $http_host can be empty. In this case, we will use
# the value of $host. See http://nginx.org/en/docs/http/ngx_http_core_module.html#var_host.
map $http_host $gw_api_compliant_host {
'' $host;
default $http_host;
}
`
1 change: 1 addition & 0 deletions internal/nginx/config/maps_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ func TestExecuteMaps(t *testing.T) {
"map ${http_my_second_add_header} $my_second_add_header_header_var {": 1,
"~.* ${http_my_second_add_header},;": 1,
"map ${http_my_set_header} $my_set_header_header_var {": 0,
"map $http_host $gw_api_compliant_host {": 1,
}

maps := string(executeMaps(conf))
Expand Down
2 changes: 1 addition & 1 deletion internal/nginx/config/servers_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ server {
{{ range $h := $l.ProxySetHeaders }}
proxy_set_header {{ $h.Name }} "{{ $h.Value }}";
{{- end }}
proxy_set_header Host $host;
proxy_set_header Host $gw_api_compliant_host;
proxy_pass {{ $l.ProxyPass }}$request_uri;
{{- end }}
}
Expand Down