You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
In Go, trying to access the Host header directly of a request object through r.Header.Get("Host") always return an empty string - regardless of whether the header is actually set or not. Instead, you need to use the r.Host field (which under the hood will just read the actual header). This leads to the X-Forwarded-Host header being left empty when requests are proxied to the cluster API Server:
This can cause problems when the API Server is fronted by some reverse proxies (e.g. NGINX) which do a strict implementation of the HTTP 1.1 protocol - where the Host (or X-Forwarded-Host) has to always be present. Otherwise, every request sends back a 400 response with an error along the following lines:
400 Bad Request: missing required Host header error
Proposed Solution
To work around the above, it should be enough to just read the Host header directly via r.Host, i.e. doing something like (note that r.Host is already set on the line above):
r.Header.Set("X-Forwarded-Host", r.Host)
The text was updated successfully, but these errors were encountered:
Problem
In Go, trying to access the
Host
header directly of a request object throughr.Header.Get("Host")
always return an empty string - regardless of whether the header is actually set or not. Instead, you need to use ther.Host
field (which under the hood will just read the actual header). This leads to theX-Forwarded-Host
header being left empty when requests are proxied to the cluster API Server:headlamp/backend/cmd/headlamp.go
Line 1010 in d4f7748
This can cause problems when the API Server is fronted by some reverse proxies (e.g. NGINX) which do a strict implementation of the HTTP 1.1 protocol - where the
Host
(orX-Forwarded-Host
) has to always be present. Otherwise, every request sends back a400
response with an error along the following lines:Proposed Solution
To work around the above, it should be enough to just read the
Host
header directly viar.Host
, i.e. doing something like (note thatr.Host
is already set on the line above):The text was updated successfully, but these errors were encountered: