Skip to content

Commit c2a97fd

Browse files
author
Kate Osborn
committed
Use http_host as proxy host when set
1 parent 890fddb commit c2a97fd

File tree

3 files changed

+11
-1
lines changed

3 files changed

+11
-1
lines changed

internal/nginx/config/maps_template.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,4 +8,13 @@ map {{ $m.Source }} {{ $m.Variable }} {
88
{{ end }}
99
}
1010
{{- end }}
11+
12+
# Set $gw_api_compliant_host variable to the value of $http_host unless $http_host is empty, then set it to the value
13+
# of $host. We prefer $http_host because it contains the original value of the host header, which is required by the
14+
# Gateway API. However, in an HTTP/1.0 request, it's possible that $http_host can be empty. In this case, we will use
15+
# the value of $host. See http://nginx.org/en/docs/http/ngx_http_core_module.html#var_host.
16+
map $http_host $gw_api_compliant_host {
17+
'' $host;
18+
default $http_host;
19+
}
1120
`

internal/nginx/config/maps_test.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ func TestExecuteMaps(t *testing.T) {
8484
"map ${http_my_second_add_header} $my_second_add_header_header_var {": 1,
8585
"~.* ${http_my_second_add_header},;": 1,
8686
"map ${http_my_set_header} $my_set_header_header_var {": 0,
87+
"map $http_host $gw_api_compliant_host {": 1,
8788
}
8889

8990
maps := string(executeMaps(conf))

internal/nginx/config/servers_template.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ server {
5050
{{ range $h := $l.ProxySetHeaders }}
5151
proxy_set_header {{ $h.Name }} "{{ $h.Value }}";
5252
{{- end }}
53-
proxy_set_header Host $host;
53+
proxy_set_header Host $gw_api_compliant_host;
5454
proxy_pass {{ $l.ProxyPass }}$request_uri;
5555
{{- end }}
5656
}

0 commit comments

Comments
 (0)