Class: Savon::Transport::Faraday
- Inherits:
-
Object
- Object
- Savon::Transport::Faraday
- 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 + )
* 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
-
.parse_cookies(headers) ⇒ Object
Parses Set-Cookie headers into a Hash of name => value.
Instance Method Summary collapse
-
#initialize(connection, globals) ⇒ Faraday
constructor
A new instance of Faraday.
-
#normalize_response(faraday_response) ⇒ Transport::Response
Normalizes a native Faraday::Response into a Transport::Response.
-
#post(url, soap_headers, body, locals) ⇒ Transport::Response
Assembles headers, executes the POST via the Faraday connection, and returns a Transport::Response.
Constructor Details
#initialize(connection, globals) ⇒ Faraday
Returns a new instance of Faraday.
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.(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 |, hash| name_value = .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.
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.
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 |