Sha256: 7ea7be981a795d69d0147354e03021b8b1ff626e067a3cf75ec43daf0a86dee9

Contents?: true

Size: 1.14 KB

Versions: 1

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      => request_uri(env)   ,
                                        :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

1 entries across 1 versions & 1 rubygems

Version Path
rest-core-3.0.0 lib/rest-core/engine/rest-client.rb