Sha256: 7e679349ac77cc7c473563d3f588b232698a79fb3f9e6b486932177ab16ee8f1

Contents?: true

Size: 1.13 KB

Versions: 4

Compression:

Stored size: 1.13 KB

Contents

require 'httpclient'
require 'rest-core/engine'

class RestCore::HttpClient < RestCore::Engine
  private
  def request promise, env
    client = ::HTTPClient.new
    client.cookie_manager = nil
    client.follow_redirect_count = 0
    client.transparent_gzip_decompression = true
    config = config_engine(env) and config.call(client)
    payload, headers = payload_and_headers(env)

    if env[HIJACK]
      request_async(client, payload, headers, promise, env)
    else
      request_sync(client, payload, headers, promise, env)
    end
  end

  def request_sync client, payload, headers, promise, env
    res = client.request(env[REQUEST_METHOD], env[REQUEST_URI], nil,
            payload, {'User-Agent' => 'Ruby'}.merge(headers))

    promise.fulfill(res.content, res.status,
                    normalize_headers(res.header.all))
  end

  def request_async client, payload, headers, promise, env
    res = client.request_async(env[REQUEST_METHOD], env[REQUEST_URI], nil,
            payload, {'User-Agent' => 'Ruby'}.merge(headers)).pop

    promise.fulfill('', res.status,
                    normalize_headers(res.header.all), res.content)
  end
end

Version data entries

4 entries across 4 versions & 1 rubygems

Version Path
rest-core-3.5.8 lib/rest-core/engine/http-client.rb
rest-core-3.5.7 lib/rest-core/engine/http-client.rb
rest-core-3.5.6 lib/rest-core/engine/http-client.rb
rest-core-3.5.5 lib/rest-core/engine/http-client.rb