lib/em-net-http.rb in em-net-http-0.3.7 vs lib/em-net-http.rb in em-net-http-0.3.8
- old
+ new
@@ -133,11 +133,12 @@
end
headers['content-type'] ||= "application/x-www-form-urlencoded"
t0 = Time.now
- httpreq = EM::HttpRequest.new(uri).send(req.class::METHOD.downcase.to_sym, opts)
+ request_method = (req.respond_to?(:method) ? req.method : req.class::METHOD).downcase.to_sym
+ httpreq = EM::HttpRequest.new(uri).send(request_method, opts)
f=Fiber.current
convert_em_http_response = lambda do |res|
emres = EM::NetHTTP::Response.new(res.response_header)
@@ -164,25 +165,25 @@
end
f.resume nhres
}
httpreq.errback {|err|f.resume(:error)}
- nhres = yield_with_error_check
+ nhres = yield_with_error_check(t0)
nhres.instance_variable_set :@httpreq, httpreq
yield nhres
nhres
else
httpreq.callback &convert_em_http_response
httpreq.errback {|err|f.resume(:error)}
- yield_with_error_check
+ yield_with_error_check(t0)
end
end
private
- def yield_with_error_check
+ def yield_with_error_check(t0)
res = Fiber.yield
if res == :error
raise 'EM::HttpRequest error - request timed out' if Time.now - self.read_timeout > t0
raise 'EM::HttpRequest error - unknown error'