I’ve found the http2 shard, but I’m having some trouble to get things working.
Has anyone some example how to do some http/2 post request?
I assume I have the HTTP2::Client properly initialised (but I am already not entirely sure about that):
context= OpenSSL::SSL::Context::Server.new
context.private_key= "/path/to/cert.key"
context.certificate_chain= "/path/to/cert.cer"
client= HTTP2::Client.new "example.com", 443, ssl_context: context
I have prepared some headers and some body I would like to post, but I wouldn’t know how.
I have tried to modify Client#request to add a parameter for the body, which I then tried to use as in
#…
stream.send_headers headers
# the next line was added
stream.send_data body
@requests[stream].receive
#…
and tried to call it like
client.request(headers, body) do |resh, resb|
p [resh, resb]
end
I don’t think I would have to modify the procedure, so I’m wondering what the correct way would be?
And this doesn’t even seem to matter yet as it won’t even reach that part yet anyway, because I constantly run into Unhandled exception in spawn: End of file reached (IO::EOFError) whenever read_frame_header gets called.
Maybe someone has some simple example of sending some data as a http2 post request!?
If it’s not clear what I even try to achieve, this is how my code would look like in ruby (using the net-http2 gem)
client= NetHttp2::Client.new "https://example.com:443", ssl_context: OpenSSL::SSL::SSLContext.new.add_certificate(OpenSSL::X509::Certificate.new(File.read "/path/to/cert.cer"), OpenSSL::PKey.read(File.read "/path/to/cert.key"))
headers= {…}
body= {…}
path= "/foo/bar"
response= client.call :post, path, body: body, headers: headers
#=> #<NetHttp2::Response:0x00007f9deba42e60 @body="…", @headers={":status"=>"200", …}>
Thanks in advance!