How can I get only response headers in an em_http_request?
I tried to use this code:
EventMachine.run do
http = EventMachine::HttpRequest.new('my_url').get
http.headers do |headers|
Fiber.current.resume headers
end
end
but I don't want to receive the whole body. How I can stop the request's execution?
http.close
doesn't work.
UPD
http.instance_variable_get(:'@conn').close
helps me, but may be you know more interesting solution
If you don't want the body, you should do a
HEAD
request instead of aGET
. To terminate the event loop you need to explicitly callEventMachine.stop
.