Skip to content

Connection header is inconsistently set to close #216

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

Open
mattbearman opened this issue May 30, 2025 · 0 comments
Open

Connection header is inconsistently set to close #216

mattbearman opened this issue May 30, 2025 · 0 comments

Comments

@mattbearman
Copy link

Depending on how you start a connection, the Connection header may be unexpectedly set to close

Creating a new instance of Net::HTTP and then calling its request method (or any of its methods that call request, eg: get) will first set the Connection header to close (if it's not already set), then start the connection, and re-call itself

Where as initiating a request with class methods, or by manually starting a connection before calling request will not set the Connection header

As the default connection in HTTP 1.1 is keep-alive, having the Connection header silently set to close is unexpected

Examples:

uri = URI('https://example.com/test')

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
req = Net::HTTP::Get.new(uri.path)
req['connection'] # => nil
res = http.request(req)
req['connection'] # => 'close'

http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.start
req = Net::HTTP::Get.new(uri.path)
req['connection'] # => nil
res = http.request(req)
req['connection'] # => nil

I've created a PR to fix this issue - #179

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

No branches or pull requests

1 participant