Class: Rack::Client::Handler::Excon
- Inherits:
-
Object
- Object
- Rack::Client::Handler::Excon
- Includes:
- DualBand
- Defined in:
- lib/rack/client/handler/excon.rb
Instance Method Summary collapse
- #async_call(env) ⇒ Object
- #connection_for(request) ⇒ Object
- #parse(excon_response) ⇒ Object
- #sync_call(env) ⇒ Object
Methods included from DualBand
Instance Method Details
#async_call(env) ⇒ Object
9 10 11 |
# File 'lib/rack/client/handler/excon.rb', line 9 def async_call(env) raise("Asynchronous API is not supported for EmHttp Handler") unless block_given? end |
#connection_for(request) ⇒ Object
40 41 42 |
# File 'lib/rack/client/handler/excon.rb', line 40 def connection_for(request) connection = ::Excon.new(request.url) end |
#parse(excon_response) ⇒ Object
31 32 33 34 35 36 37 38 |
# File 'lib/rack/client/handler/excon.rb', line 31 def parse(excon_response) body = excon_response.body.empty? ? [] : StringIO.new(excon_response.body) headers = {} excon_response.headers.map do |key,value| headers[key] = value.split(", ") end Response.new(excon_response.status, Headers.new(headers).to_http, body) end |
#sync_call(env) ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/rack/client/handler/excon.rb', line 13 def sync_call(env) request = Rack::Request.new(env) body = case request.body when StringIO then request.body.string when IO then request.body.read when Array then request.body.join when String then request.body end response = parse connection_for(request).request(:method => request.request_method, :path => request.path, :headers => Headers.from(env).to_http, :body => body) response.finish end |