Class: Savon::Transport::Faraday

Inherits:
Object
  • Object
show all
Includes:
Logging
Defined in:
lib/savon/transport/faraday.rb

Overview

Faraday-backed HTTP transport for the opt-in Faraday path.

Encapsulates everything Faraday-specific:

* header assembly (SOAP + global + local + cookies)
* request execution via the caller-configured Faraday::Connection

Transport-level concerns (SSL, auth, proxy, timeouts, middleware) are the caller's responsibility via client.faraday before any call is made.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(connection, globals) ⇒ Faraday

Returns a new instance of Faraday.

Parameters:

  • connection (Faraday::Connection)

    the memoized connection from client.faraday

  • globals (Savon::GlobalOptions)

    the client-level options



21
22
23
24
# File 'lib/savon/transport/faraday.rb', line 21

def initialize(connection, globals)
  @connection = connection
  @globals    = globals
end

Class Method Details

.parse_cookies(headers) ⇒ Object

Parses Set-Cookie headers into a Hash of name => value. Accepts both the Array and String form. Attributes after the first ';' are discarded.



57
58
59
60
61
62
63
64
65
66
67
# File 'lib/savon/transport/faraday.rb', line 57

def self.parse_cookies(headers)
  raw = headers["set-cookie"] || headers["Set-Cookie"]
  return {} unless raw

  raw_array = raw.is_a?(Array) ? raw : raw.split(/,\s*/)
  raw_array.each_with_object({}) do |cookie_str, hash|
    name_value = cookie_str.split(";", 2).first.to_s.strip
    name, value = name_value.split("=", 2)
    hash[name] = value if name && !name.empty?
  end
end

Instance Method Details

#normalize_response(faraday_response) ⇒ Transport::Response

Normalizes a native Faraday::Response into a Transport::Response.

Parameters:

  • faraday_response (Faraday::Response)

Returns:



51
52
53
# File 'lib/savon/transport/faraday.rb', line 51

def normalize_response(faraday_response)
  Response.from_faraday(faraday_response)
end

#post(url, soap_headers, body, locals) ⇒ Transport::Response

Assembles headers, executes the POST via the Faraday connection, and returns a Transport::Response. Logs the outbound request and inbound response when logging is enabled.

Parameters:

  • url (String)

    the SOAP endpoint URL

  • soap_headers (Hash)

    SOAP-level headers (Content-Type, SOAPAction, etc.)

  • body (String)

    the serialized SOAP envelope

  • locals (Savon::LocalOptions)

    per-request options

Returns:



35
36
37
38
39
40
41
42
43
44
45
# File 'lib/savon/transport/faraday.rb', line 35

def post(url, soap_headers, body, locals)
  headers = build_headers(soap_headers, locals)

  log_request(url, headers, body) if log?

  faraday_response = @connection.post(url, body, headers)
  response = normalize_response(faraday_response)

  log_response(response) if log?
  response
end