Module: Linzer::Faraday::Utils

Defined in:
lib/linzer/faraday/utils.rb

Overview

Utility methods for converting Faraday middleware objects into types compatible with Linzer adapters.

Class Method Summary collapse

Class Method Details

.create_request(env) ⇒ ::Faraday::Request

Creates a Faraday::Request from a middleware environment.

Builds a minimal request suitable for use with Message::Adapter::Faraday::Request, preserving the original HTTP method, URL, and headers from the environment.

Preserves the environment's request options when present, so that a params_encoder configured on the connection or request is carried over. The adapter re-encodes query parameters when deriving @target-uri and friends, and must use the same encoder Faraday used to write the URL, or the signed value will not match the URI actually sent.

Parameters:

  • env (::Faraday::Env)

    the middleware environment

Returns:

  • (::Faraday::Request)

    a new request object



26
27
28
29
30
31
32
33
# File 'lib/linzer/faraday/utils.rb', line 26

def self.create_request(env)
  ::Faraday::Request.create(env.method) do |req|
    req.params  = ::Faraday::Utils::ParamsHash.new
    req.headers = ::Faraday::Utils::Headers.new(env.request_headers.dup)
    req.options = env.request || ::Faraday::ConnectionOptions.from(nil).request
    req.url       env.url
  end
end