Sha256: a3c2ea1389687ebd3e5c3981fe2a1a3473ee8613c436514197062fbbb1b9a579

Contents?: true

Size: 1.14 KB

Versions: 7

Compression:

Stored size: 1.14 KB

Contents

require 'restclient'
require 'rest-core/patch/rest-client'
require 'rest-core/engine'

class RestCore::RestClient < RestCore::Engine
  def request promise, env
    open_timeout, read_timeout = calculate_timeout(env[TIMER])
    payload, headers = payload_and_headers(env)
    res = ::RestClient::Request.execute(:method   => env[REQUEST_METHOD],
                                        :url      => env[REQUEST_URI]   ,
                                        :payload  => payload            ,
                                        :headers  => headers            ,
                                        :max_redirects => 0             ,
                                        :open_timeout => open_timeout   ,
                                             :timeout => read_timeout   )
    promise.fulfill(res.body, res.code, normalize_headers(res.raw_headers))
  rescue ::RestClient::Exception => e
    if res = e.response
      # we don't want to raise an exception for 404 requests
      promise.fulfill(res.body, res.code, normalize_headers(res.raw_headers))
    else
      promise.reject(e)
    end

  rescue Exception => e
    promise.reject(e)
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
rest-core-3.3.3 lib/rest-core/engine/rest-client.rb
rest-core-3.3.2 lib/rest-core/engine/rest-client.rb
rest-core-3.3.1 lib/rest-core/engine/rest-client.rb
rest-core-3.3.0 lib/rest-core/engine/rest-client.rb
rest-core-3.2.0 lib/rest-core/engine/rest-client.rb
rest-core-3.1.1 lib/rest-core/engine/rest-client.rb
rest-core-3.1.0 lib/rest-core/engine/rest-client.rb