lib/em-net-http.rb in em-net-http-0.1.1 vs lib/em-net-http.rb in em-net-http-0.1.2
- old
+ new
@@ -62,23 +62,32 @@
module Net
class HTTP
def request(req, body = nil, &block)
f=Fiber.current
uri = Addressable::URI.parse("#{use_ssl? ? 'https://' : 'http://'}#{addr_port}#{req.path}")
+ body = body || req.body
opts = body.nil? ? {} : {:body => body}
if use_ssl?
sslopts = opts[:ssl] = {}
sslopts[:verify_peer] = verify_mode == OpenSSL::SSL::VERIFY_PEER
sslopts[:private_key_file] = key if key
sslopts[:cert_chain_file] = ca_file if ca_file
end
+ headers = opts[:head] = {}
+ req.each do |k, v|
+ headers[k] = v
+ end
+ headers['content-type'] ||= "application/x-www-form-urlencoded"
httpreq = EM::HttpRequest.new(uri).send(req.class::METHOD.downcase.to_sym, opts)
httpreq.callback {|res|f.resume(EM::NetHTTPResponse.new(res))}
httpreq.errback {|res|f.resume(EM::NetHTTPResponse.new(res))}
res = Fiber.yield
yield res if block_given?
res
end
end
end
+
+# Other bits and bobs.
+