internal/log: return full X-Forwarded-For

Signed-off-by: Bobby DeSimone <bobbydesimone@gmail.com>
This commit is contained in:
Bobby DeSimone 2019-09-28 12:15:13 -07:00
parent 218d157fce
commit 33d4e4843b
No known key found for this signature in database
GPG key ID: AEE4CF12FE86D07E
3 changed files with 14 additions and 16 deletions

View file

@ -253,18 +253,18 @@ func BenchmarkDataRace(b *testing.B) {
func TestForwardedAddrHandler(t *testing.T) {
out := &bytes.Buffer{}
r := &http.Request{
Header: http.Header{
"X-Forwarded-For": []string{"client", "proxy1", "proxy2"},
},
}
r := httptest.NewRequest(http.MethodGet, "/", nil)
r.Header.Set("X-Forwarded-For", "proxy1,proxy2,proxy3")
h := ForwardedAddrHandler("fwd_ip")(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
l := FromRequest(r)
l.Log().Msg("")
}))
h = NewHandler(zerolog.New(out))(h)
h.ServeHTTP(nil, r)
if want, got := `{"fwd_ip":"client"}`+"\n", decodeIfBinary(out); want != got {
if want, got := `{"fwd_ip":["proxy1","proxy2","proxy3"]}`+"\n", decodeIfBinary(out); want != got {
t.Errorf("Invalid log output, got: %s, want: %s", got, want)
}
}