class Faraday::Adapter::HTTPClient

def call(env)

def call(env)
  super
  # enable compression
  client.transparent_gzip_decompression = true
  if req = env[:request]
    if proxy = req[:proxy]
      configure_proxy proxy
    end
    if bind = req[:bind]
      configure_socket bind
    end
    configure_timeouts req
  end
  if env[:url].scheme == 'https' && ssl = env[:ssl]
    configure_ssl ssl
  end
  configure_client
  # TODO Don't stream yet.
  # https://github.com/nahi/httpclient/pull/90
  env[:body] = env[:body].read if env[:body].respond_to? :read
  resp = client.request env[:method], env[:url],
    :body   => env[:body],
    :header => env[:request_headers]
  save_response env, resp.status, resp.body, resp.headers, resp.reason
  @app.call env
rescue ::HTTPClient::TimeoutError, Errno::ETIMEDOUT
  raise Faraday::Error::TimeoutError, $!
rescue ::HTTPClient::BadResponseError => err
  if err.message.include?('status 407')
    raise Faraday::Error::ConnectionFailed, %{407 "Proxy Authentication Required "}
  else
    raise Faraday::Error::ClientError, $!
  end
rescue Errno::ECONNREFUSED, IOError
  raise Faraday::Error::ConnectionFailed, $!
rescue => err
  if defined?(OpenSSL) && OpenSSL::SSL::SSLError === err
    raise Faraday::SSLError, err
  else
    raise
  end
end