-
Notifications
You must be signed in to change notification settings - Fork 13
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
http_proxy: print proxy errors in response body #502
Conversation
Can it be like
|
Also, check the response headers, the proxy name must be both in headers and body. |
d110361
to
88571ba
Compare
http_proxy_errors.go
Outdated
var body bytes.Buffer | ||
body.WriteString(hp.config.Name) | ||
body.WriteString(" ") | ||
body.WriteString(strings.ToLower(msg)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about we fixed the messages so that they do not start with upper case?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
88571ba
to
f30c1c4
Compare
http_proxy_errors.go
Outdated
@@ -121,7 +130,7 @@ func handleStatusText(req *http.Request, err error) (code int, msg, label string | |||
if req.URL.Scheme == "https" && err != nil { | |||
for i := 400; i < 600; i++ { | |||
if err.Error() == http.StatusText(i) { | |||
return i, err.Error(), "https_status_text" | |||
return i, strings.ToLower(err.Error()), "https_status_text" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's add some text here, "encountered an unexpected internal error: "
f30c1c4
to
e837a56
Compare
http_proxy_errors.go
Outdated
@@ -121,7 +130,8 @@ func handleStatusText(req *http.Request, err error) (code int, msg, label string | |||
if req.URL.Scheme == "https" && err != nil { | |||
for i := 400; i < 600; i++ { | |||
if err.Error() == http.StatusText(i) { | |||
return i, err.Error(), "https_status_text" | |||
msg = fmt.Sprintf("encountered an unexpected internal error: %s", strings.ToLower(err.Error())) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So do we need strings.ToLower
here?
http_proxy_errors.go
Outdated
@@ -50,16 +51,24 @@ func (hp *HTTPProxy) errorResponse(req *http.Request, err error) *http.Response | |||
} | |||
if code == 0 { | |||
code = http.StatusInternalServerError | |||
msg = "An unexpected error occurred" | |||
msg = "an unexpected error occurred" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This does not play well with config.Name
a8ec8e3
to
00acc8b
Compare
00acc8b
to
118145f
Compare
e2e/tests/proxy_test.go
Outdated
|
||
// Check if the error message is correctly propagated to the client. | ||
// Especially when several proxies are chained. | ||
if !strings.Contains(string(res.Body), expectedErrorMessage) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Nah, just skip it if MITM is enabled.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The issue is that our current httpexpect implementation also does the same trick, so all https requests made by the client do not return an original response in case of a connect error.
func (c *Client) do(req *http.Request) (*http.Response, error) {
if c.trace != nil {
req = req.WithContext(httptrace.WithClientTrace(req.Context(), c.trace))
}
resp, err := c.rt.RoundTrip(req)
// There is a difference between sending HTTP and HTTPS requests.
// For HTTPS client issues a CONNECT request to the proxy and then sends the original request.
// In case the proxy responds with status code 4XX or 5XX to the CONNECT request, the client interprets it as URL error.
//
// This is to cover this case.
if req.URL.Scheme == "https" && err != nil {
for i := 400; i < 600; i++ {
if err.Error() == http.StatusText(i) {
return &http.Response{
StatusCode: i,
Status: http.StatusText(i),
ProtoMajor: 1,
ProtoMinor: 1,
Header: http.Header{},
Body: http.NoBody,
Request: req,
}, nil
}
}
}
return resp, err
}
Solution 1. is to keep this test and later address it in both proxy http client and our http expect client.
Solution 2. is to limit the scope and make it a dedicated MITM flag test.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I actually wanted to print a warning there, but I'm afraid, it won't be visible in a non-debug mode. So there we have this "half skip" - it always checks the status code.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Add text checking only for http requests.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ok
50f5d7e
to
2df651f
Compare
2df651f
to
089e920
Compare
Responses will now contain proxy name and error:
First line is a generic message, second the error.
Header: