ostinelli / net-http2

NetHttp2 is an HTTP/2 client for Ruby.
MIT License
141 stars 31 forks source link

headers does not work #26

Open mvalitov opened 6 years ago

mvalitov commented 6 years ago

with headers:

require 'net-http2'
# create a client
client = NetHttp2::Client.new("https://nghttp2.org")
# send request
response = client.call(:get, '/httpbin/headers', headers: { 'x-custom' => 'custom' })
# read the response
response.ok?      # => false
response.status   # => nil
response.headers  # => {}
response.body     # => ""
# close the connection
client.close

without headers:

require 'net-http2'
# create a client
client = NetHttp2::Client.new("https://nghttp2.org")
# send request
response = client.call(:get, '/httpbin/headers')
# read the response
response.ok?      # => true
response.status   # => '200'
response.headers  # => {":status"=>"200", "date"=>"Thu, 12 Apr 2018 11:01:10 GMT", "content-type"=>"application/json", "content-length"=>"77", "access-control-allow-origin"=>"*", "access-control-allow-credentials"=>"true", "x-backend-header-rtt"=>"0.003101", "strict-transport-security"=>"max-age=31536000", "server"=>"nghttpx", "via"=>"1.1 nghttpx", "x-frame-options"=>"SAMEORIGIN", "x-xss-protection"=>"1; mode=block", "x-content-type-options"=>"nosniff"}
response.body     # => "{\n  \"headers\": {\n    \"Host\": \"nghttp2.org:443\",\n    \"Via\": \"2 nghttpx\"\n  }\n}\n"
# close the connection
client.close
mvalitov commented 6 years ago

Hm, but if you do so:

response = client.call(:get, '/httpbin/headers', headers: {
':scheme' => 'https', 
':method' => 'get', 
':path' => 'nghttp2.org',
':authority' => 'nghttp2.org:443', 
'x-custom' => 'custom' })

then all ok