Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update flashlight to pass as is HTTP responses with certain 4xx status codes #1121

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 15 additions & 0 deletions proxied/proxied.go
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,17 @@ func success(resp *http.Response) bool {
return resp.StatusCode > 199 && resp.StatusCode < 400
}

// clientError checks if the given HTTP response has a
// 400 or 401 response code; if so, the response is passed
// as is. Note: we don't treat all 4xx client errors this way
// because our fronted servers return some 403 Forbidden
// whenever use a masquerade host on which domain
// fronting doesn't work
func clientError(resp *http.Response) bool {
return resp.StatusCode == http.StatusUnauthorized ||
resp.StatusCode == http.StatusBadRequest
}

// changeUserAgent prepends app version and OSARCH to the User-Agent header
// of req to facilitate debugging on server side.
func changeUserAgent(req *http.Request) {
Expand Down Expand Up @@ -284,6 +295,10 @@ func (df *dualFetcher) do(req *http.Request, chainedRT http.RoundTripper, ddfRT
log.Debugf("Got successful HTTP call!")
responses <- resp
return resp, nil
} else if clientError(resp) {
log.Debugf("Got HTTP response with client error (%d status code). Passing response as is", resp.StatusCode)
responses <- resp
return resp, nil
}
// If the local proxy can't connect to any upstream proxies, for example,
// it will return a 502.
Expand Down