HoneyryderChuck / httpx

(Mirror) An HTTP client library for ruby
https://gitlab.com/os85/httpx
Apache License 2.0
192 stars 10 forks source link

Does HTTP2 Multiplexing return the responses in the same order as the requests? #29

Closed Aubermean closed 11 months ago

Aubermean commented 11 months ago

Without the idiot proof Typhoeus on_complete callbacks, I am looking at the best way to handle responses.

  def execute(qty)
    requests = []
    generate_params(qty).each do |params|
      requests << ['POST', 'https://api.blahblah.com/api/v2/search', { json: params }]
    end
    responses = @httpx.bearer_auth('BLAHBLAH').request(requests, max_concurrent_requests: 25)
  ensure
    responses = [responses] unless responses.is_a?(Array) # so I can do qty=1
    requests.zip(responses).each do |request, response|
      process_response(request, response)
    end
  end

This seems to work, with the caveat that if one request fails none are processed. But to be sure, can I double check and ask if HTTP2 Multiplexing with HTTPX always returns the responses in the right order, so my requests.zip(responses) won't cause any surprises? Thanks!

HoneyryderChuck commented 11 months ago

Hi,

Yes, order is guaranteed. They're also handled independently, I.e. one failing will not influence the rest (at least with HTTP/2, and of course depending on the server).

Closing, as it's not an issue.