Interesting, that’s not what I’m seeing in my app. I’ve got this code, with debug logging added, which tries to re-assemble the incoming request URL:
func getURL(r *http.Request) *url.URL {
log.Printf("XXX getURL: r.URL=%q", r.URL)
log.Printf("XXX getURL: r.URL.Host=%q", r.URL.Host)
log.Printf("XXX getURL: r.Host=%q", r.Host)
log.Printf("XXX getURL: r.Header.Get(\"Host\")=%q", r.Header.Get("Host"))
log.Printf("XXX getURL: r.Headers=%#v", r.Header)
scheme := r.Header.Get("X-Forwarded-Proto")
if scheme == "" {
scheme = r.Header.Get("X-Forwarded-Protocol")
}
if scheme == "" && r.Header.Get("X-Forwarded-Ssl") == "on" {
scheme = "https"
}
if scheme == "" && r.TLS != nil {
scheme = "https"
}
if scheme == "" {
scheme = "http"
}
host := r.URL.Host
if host == "" {
host = r.Host
}
return &url.URL{
Scheme: scheme,
Opaque: r.URL.Opaque,
User: r.URL.User,
Host: host,
Path: r.URL.Path,
RawPath: r.URL.RawPath,
ForceQuery: r.URL.ForceQuery,
RawQuery: r.URL.RawQuery,
Fragment: r.URL.Fragment,
}
}
When I make a curl --http2
request, I see this in the logs, which shows r.Host
and r.Header.Get("Host")
both having a value of 172.19.0.26:8080
:
2024-09-24T21:20:58.638 app[5683594a146648] dfw [info] 2024/09/24 21:20:58 XXX getURL: r.URL="/get?v=New+York"
2024-09-24T21:20:58.638 app[5683594a146648] dfw [info] 2024/09/24 21:20:58 XXX getURL: r.URL.Host=""
2024-09-24T21:20:58.638 app[5683594a146648] dfw [info] 2024/09/24 21:20:58 XXX getURL: r.Host="172.19.0.26:8080"
2024-09-24T21:20:58.638 app[5683594a146648] dfw [info] 2024/09/24 21:20:58 XXX getURL: r.Header.Get("Host")="172.19.0.26:8080"
2024-09-24T21:20:58.638 app[5683594a146648] dfw [info] 2024/09/24 21:20:58 XXX getURL: r.Headers=http.Header{"Accept":[]string{"*/*"}, "Fly-Client-Ip":[]string{"2601:19e:8200:e6d0::72f2"}, "Fly-Forwarded-Port":[]string{"443"}, "Fly-Forwarded-Proto":[]string{"https"}, "Fly-Forwarded-Ssl":[]string{"on"}, "Fly-Region":[]string{"bos"}, "Fly-Request-Id":[]string{"01J8JYHB7VT2MQPCDQKSMYDCA5-bos"}, "Fly-Traceparent":[]string{"00-998435d8ef7838aa48ad8f290a50851c-ae4dc48b47d48d67-00"}, "Fly-Tracestate":[]string{""}, "Host":[]string{"172.19.0.26:8080"}, "User-Agent":[]string{"curl/8.7.1"}, "Via":[]string{"2 fly.io"}, "X-Forwarded-For":[]string{"2601:19e:8200:e6d0::72f2, 2a09:8280:1::47:e4e2:0"}, "X-Forwarded-Port":[]string{"443"}, "X-Forwarded-Proto":[]string{"https"}, "X-Forwarded-Ssl":[]string{"on"}, "X-Request-Start":[]string{"t=1727212858619402"}}
A curl --http1.1
request on the other hand works as expected:
2024-09-24T21:25:43.962 app[5683594a146648] dfw [info] 2024/09/24 21:25:43 XXX getURL: r.URL="/get?v=New+York"
2024-09-24T21:25:43.962 app[5683594a146648] dfw [info] 2024/09/24 21:25:43 XXX getURL: r.URL.Host=""
2024-09-24T21:25:43.962 app[5683594a146648] dfw [info] 2024/09/24 21:25:43 XXX getURL: r.Host="httpbingo-test.fly.dev"
2024-09-24T21:25:43.962 app[5683594a146648] dfw [info] 2024/09/24 21:25:43 XXX getURL: r.Header.Get("Host")="httpbingo-test.fly.dev"
2024-09-24T21:25:43.962 app[5683594a146648] dfw [info] 2024/09/24 21:25:43 XXX getURL: r.Headers=http.Header{"Accept":[]string{"*/*"}, "Fly-Client-Ip":[]string{"2601:19e:8200:e6d0::72f2"}, "Fly-Forwarded-Port":[]string{"443"}, "Fly-Forwarded-Proto":[]string{"https"}, "Fly-Forwarded-Ssl":[]string{"on"}, "Fly-Region":[]string{"bos"}, "Fly-Request-Id":[]string{"01J8JYT10KHM700QM7RP7RW5TK-bos"}, "Fly-Traceparent":[]string{"00-ad16c715554689f92edd860222e1a1b4-14da2c2558897bff-00"}, "Fly-Tracestate":[]string{""}, "Host":[]string{"httpbingo-test.fly.dev"}, "User-Agent":[]string{"curl/8.7.1"}, "Via":[]string{"1.1 fly.io"}, "X-Forwarded-For":[]string{"2601:19e:8200:e6d0::72f2, 2a09:8280:1::47:e4e2:0"}, "X-Forwarded-Port":[]string{"443"}, "X-Forwarded-Proto":[]string{"https"}, "X-Forwarded-Ssl":[]string{"on"}, "X-Request-Start":[]string{"t=1727213143060047"}}
Any idea why I’m seeing different behavior here?