-
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
Fix content length in CONNECT requests and responses #866
Conversation
This is for compatibility between conn and handler versions. Also, handler version sets content length for http/2 to indicate that there will be DATA frames.
83ece87
to
5659193
Compare
internal/martian/proxy_connect.go
Outdated
|
||
func newConnectResponse(req *http.Request) *http.Response { | ||
return &http.Response{ | ||
StatusCode: http.StatusOK, |
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.
Please set Status
too. The response log lacks it, you can see it in commit message.
sc-1 | HTTP/2.0
vs
sc-server-1 | HTTP/1.1 200 OK
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.
Done and donner
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.
Wrong 🤔. That's how it's done in proxyutil
Status: fmt.Sprintf("%d %s", code, http.StatusText(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.
That is the best way of doing it, fixed.
50184fd
to
0e79abf
Compare
res.ContentLength = -1 // Do we still need that?
if err := p.tunnel("CONNECT", res, crw); err != nil {
log.Errorf(ctx, "CONNECT tunnel: %v", err)
} I wonder if we still need that, since we set the ContentLength in read. I understand this is just a sanity check if the ContentLength was modified in Martian req/res modifiers? |
I'd leave that to be on the safe side, we can add some logging. |
Sure, let's log it. |
Without this patch we (the net/http package) assume any request content length without Content-Length header is 0. This is not the case for CONNECT requests.
Make CONNECT response use http.NoBody and ConetentLenth = -1 Logs from Sauce Connect showing clean CONNECT requests and responses when using this patch. sc-1 | CONNECT //cdn.cookielaw.org:443 HTTP/2.0 sc-1 | Host: cdn.cookielaw.org:443 sc-1 | Sl-Forwarded-Host: cdn.cookielaw.org:443 sc-1 | Sl-Forwarded-Proto: sc-1 | User-Agent: curl/8.6.0 sc-1 | Via: 1.1 sc_server-159f7f75742d33630cfc, 2.0 sauce_connect-e31d884000ef4e50a1a0 sc-1 | sc-1 | HTTP/2.0 OK sc-1 | sc-1 | ... sc-server-1 | CONNECT https://cdn.cookielaw.org:443 HTTP/1.1 sc-server-1 | Host: cdn.cookielaw.org:443 sc-server-1 | Sl-Forwarded-Host: cdn.cookielaw.org:443 sc-server-1 | Sl-Forwarded-Proto: sc-server-1 | User-Agent: curl/8.6.0 sc-server-1 | Via: 1.1 sc_server-159f7f75742d33630cfc sc-server-1 | sc-server-1 | HTTP/1.1 200 OK sc-server-1 | sc-server-1 |
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.
LGTM
Make sure that we correctly read and send Content-Length header value for CONNECT requests.