igrigorik / em-http-request

Asynchronous HTTP Client (EventMachine + Ruby)
1.22k stars 220 forks source link

Cancel an HTTP request #326

Closed hartator closed 6 years ago

hartator commented 6 years ago

Let's say I am using multiples proxies to get the same page via EventMachine::MultiRequest.new.

Something like this:

EventMachine.run do
  multi = EventMachine::MultiRequest.new

  multi.add :google_1, EventMachine::HttpRequest.new('http://www.google.com/', connection_opts_1).get
  multi.add :google_2, EventMachine::HttpRequest.new('http://www.google.com/', connection_opts_1).get
end

Is there a way to cancel the other request when the other one successfully get the result first?

Thanks for awesome work on this gem btw.

igrigorik commented 6 years ago

Sadly, not really. See: https://github.com/igrigorik/em-http-request/issues/256

In http/2, you can reset a stream, but in http/1.. not so much.

hartator commented 6 years ago

Thanks for the answer!