Skip to content

Commit

Permalink
only set header when it is not empty (#380)
Browse files Browse the repository at this point in the history
  • Loading branch information
magiconair committed Nov 30, 2017
1 parent 96adb21 commit 934f25a
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 20 deletions.
2 changes: 1 addition & 1 deletion proxy/http_headers.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ func addHeaders(r *http.Request, cfg config.Proxy, stripPath string) error {
r.Header.Set("X-Forwarded-Port", localPort(r))
}

if r.Header.Get("X-Forwarded-Host") == "" {
if r.Header.Get("X-Forwarded-Host") == "" && r.Host != "" {
r.Header.Set("X-Forwarded-Host", r.Host)
}

Expand Down
19 changes: 0 additions & 19 deletions proxy/http_headers_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Port": []string{"80"},
"X-Forwarded-Prefix": []string{"/foo"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -51,7 +50,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"https"},
"X-Forwarded-Port": []string{"443"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -67,7 +65,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"http"},
"X-Forwarded-Port": []string{"80"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -83,7 +80,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"https"},
"X-Forwarded-Port": []string{"443"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -98,7 +94,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"http"},
"X-Forwarded-Port": []string{"80"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -112,7 +107,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"http"},
"X-Forwarded-Port": []string{"80"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -126,7 +120,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"https"},
"X-Forwarded-Port": []string{"443"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -140,7 +133,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"https"},
"X-Forwarded-Port": []string{"443"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -154,7 +146,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"http"},
"X-Forwarded-Port": []string{"80"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -168,7 +159,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"http"},
"X-Forwarded-Port": []string{"80"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -183,7 +173,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"https"},
"X-Forwarded-Port": []string{"443"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -198,7 +187,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"https"},
"X-Forwarded-Port": []string{"443"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -213,7 +201,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"https"},
"X-Forwarded-Port": []string{"443"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -227,7 +214,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"http"},
"X-Forwarded-Port": []string{"80"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -241,7 +227,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"some value"},
"X-Forwarded-Port": []string{"80"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -255,7 +240,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"some value"},
"X-Forwarded-Port": []string{"80"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -269,7 +253,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"some value"},
"X-Forwarded-Port": []string{"80"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand All @@ -289,7 +272,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"other value"},
"X-Forwarded-Port": []string{"80"},
"X-Real-Ip": []string{"1.2.3.4"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand Down Expand Up @@ -373,7 +355,6 @@ func TestAddHeaders(t *testing.T) {
"X-Forwarded-Proto": []string{"http"},
"X-Forwarded-Port": []string{"80"},
"X-Real-Ip": []string{"6.6.6.6"},
"X-Forwarded-Host": []string{""},
},
"",
},
Expand Down

0 comments on commit 934f25a

Please sign in to comment.