net-http2 icon indicating copy to clipboard operation
net-http2 copied to clipboard

headers does not work

Open mvalitov opened this issue 6 years ago • 1 comments

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 avatar Apr 12 '18 11:04 mvalitov

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

mvalitov avatar Apr 12 '18 15:04 mvalitov