socketry / async-http

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Unexpected response headers in HTTP1.0

guppy0356 opened this issue Β· comments

I try to contribute to webmock to fix InvalidURIError on bblimke/webmock#890. I found unexpected response headers in Travis CI result.
πŸ‘‰ https://travis-ci.org/github/bblimke/webmock/jobs/696308825

Is it normal for response headers to contain keep-alive in http1.0 ? I think a832d02 has affect this response.

If possible can you show me the full request and response details.

Yes, HTTP/1.0 requires Connection: keep-alive for persistent connections.

@ioquatix

I'm sorry to be late. I tried this program in Ruby 2.6.3.

require 'webmock'
include WebMock::API

WebMock.enable!

stub_request(:get, 'www.example.com').to_return(body: 'hi, there!')

result = Async do
  endpoint = Async::HTTP::Endpoint.parse('http://www.example.com')

  begin
    Async::HTTP::Client.open(endpoint, Async::HTTP::Protocol::HTTP10) do |client|
      response = client.send(
        :get,
        endpoint.path,
        {},
        nil
      )

      {
        status: response.status,
        headers: response.headers.to_h,
        body: response.read
      }
    end
  rescue Async::TimeoutError => e
    e
  end
end.wait

p result #=> {:status=>200, :headers=>{"connection"=>["keep-alive"]}, :body=>"hi, there!"}

That looks correct to me. It would probably make sense to scrub connection headers (and per-hop)
headers from the response if you are computing a checksum/hash.

@ioquatix
thank you for your cooperation.

You are most welcome!