Skip to content

Omit Content-Length on a successful CONNECT response - #237

Open
adityawrk wants to merge 2 commits into
ruby:masterfrom
adityawrk:fix/connect-no-content-length
Open

adityawrk wants to merge 2 commits into
ruby:masterfrom
adityawrk:fix/connect-no-content-length

Conversation

@adityawrk

Copy link
Copy Markdown

Fixes #87.

RFC 9110 says a server must not send Content-Length or Transfer-Encoding on a 2xx response to CONNECT. The response is the start of a tunnel, not a message with a body. WEBrick still filled in Content-Length: 0 because the response body was an empty string.

A raw request before the change:

CONNECT 127.0.0.1:port HTTP/1.1

HTTP/1.1 200 OK
Content-Length: 0
Connection: close

After the change the same request has no Content-Length and no Transfer-Encoding, and bytes written next are delivered to the origin (ping / pong). A CONNECT that fails to open the upstream socket is still an ordinary error response and still carries Content-Length.

bundle exec rake test: 158 tests, 838 assertions.

RFC 9110 forbids Content-Length and Transfer-Encoding on a 2xx
response to CONNECT. WEBrick sent Content-Length: 0, which some
clients treat as an empty body instead of a tunnel.
A 2xx response to CONNECT starts a tunnel and is not a message
with a body. The response setup now drops Content-Length and
Transfer-Encoding for that case, and still sends them on a
failed CONNECT.

Fixes ruby#87

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

HTTPProxyServer should not send Content-Length header in successful responses to CONNECT requests

1 participant