Something went wrong. Try again.
sloproxy
Something went wrong. Try again.
1.4 kB · 34 lines
Go
at main
1234567891011121314151617181920212223242526272829303132333435package logging
import ( "context" "net/http" "testing")
func TestWithFreshResponseHeadersHolderIsolatesAttempts(t *testing.T) { requestCtx := WithResponseHeadersHolder(context.Background()) SetResponseHeaders(requestCtx, http.Header{"X-Upstream-Attempt": []string{"request"}})
firstAttemptCtx := WithFreshResponseHeadersHolder(requestCtx) if headers := GetResponseHeaders(firstAttemptCtx); len(headers) != 0 { t.Fatalf("fresh attempt inherited request headers: %#v", headers) } SetResponseHeaders(firstAttemptCtx, http.Header{"X-Upstream-Attempt": []string{"first"}})
secondAttemptCtx := WithFreshResponseHeadersHolder(firstAttemptCtx) if headers := GetResponseHeaders(secondAttemptCtx); len(headers) != 0 { t.Fatalf("second attempt inherited first attempt headers: %#v", headers) } SetResponseHeaders(secondAttemptCtx, http.Header{"X-Upstream-Attempt": []string{"second"}})
if got := GetResponseHeaders(requestCtx).Get("X-Upstream-Attempt"); got != "request" { t.Fatalf("request holder = %q, want request", got) } if got := GetResponseHeaders(firstAttemptCtx).Get("X-Upstream-Attempt"); got != "first" { t.Fatalf("first attempt holder = %q, want first", got) } if got := GetResponseHeaders(secondAttemptCtx).Get("X-Upstream-Attempt"); got != "second" { t.Fatalf("second attempt holder = %q, want second", got) }}