Skip to content

Commit

Permalink
Use http_host as proxy host when set
Browse files Browse the repository at this point in the history
  • Loading branch information
kate-osborn committed Jul 7, 2023
1 parent 890fddb commit c2a97fd
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 1 deletion.
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

0 comments on commit c2a97fd

Please sign in to comment.