Skip to content

Commit 66a9448

Browse files
committed
fix: respect more http sources for computing request URL
1 parent e572e81 commit 66a9448

File tree

2 files changed

+9
-1
lines changed

2 files changed

+9
-1
lines changed

x/http.go

+6-1
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,12 @@ func EasyCookieJar(t *testing.T, o *cookiejar.Options) *cookiejar.Jar {
6161

6262
func RequestURL(r *http.Request) *url.URL {
6363
source := *r.URL
64-
source.Host = stringsx.Coalesce(source.Host, r.Host)
64+
source.Host = stringsx.Coalesce(source.Host, r.Header.Get("X-Forwarded-Host"), r.Host)
65+
66+
if proto := r.Header.Get("X-Forwarded-Proto"); len(proto) > 0 {
67+
source.Scheme = proto
68+
}
69+
6570
if source.Scheme == "" {
6671
source.Scheme = "https"
6772
if r.TLS == nil {

x/http_test.go

+3
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,9 @@ func TestRequestURL(t *testing.T) {
2626
assert.EqualValues(t, RequestURL(&http.Request{
2727
URL: urlx.ParseOrPanic("/foo"), Host: "foobar",
2828
}).String(), "http://foobar/foo")
29+
assert.EqualValues(t, RequestURL(&http.Request{
30+
URL: urlx.ParseOrPanic("/foo"), Host: "foobar", Header: http.Header{"X-Forwarded-Host": []string{"notfoobar"}, "X-Forwarded-Proto": {"https"}},
31+
}).String(), "https://notfoobar/foo")
2932
}
3033

3134
func TestAcceptToRedirectOrJSON(t *testing.T) {

0 commit comments

Comments
 (0)