Class: Savon::Transport::HTTPI

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

Overview

HTTPI-backed HTTP transport for the default HTTP path.

Encapsulates everything HTTPI-specific:

* header assembly
* proxy/SSL/auth/timeout configuration
* request execution

Instance Method Summary collapse

Constructor Details

#initialize(globals) ⇒ HTTPI

Returns a new instance of HTTPI.

Parameters:



19
20
21
# File 'lib/savon/transport/httpi.rb', line 19

def initialize(globals)
  @globals = globals
end

Instance Method Details

#normalize_response(httpi_response) ⇒ Transport::Response

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

Parameters:

  • httpi_response (HTTPI::Response)

Returns:



47
48
49
# File 'lib/savon/transport/httpi.rb', line 47

def normalize_response(httpi_response)
  Response.from_httpi(httpi_response)
end

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

Assembles and executes a SOAP request, returning 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

  • body (String)

    the serialized SOAP envelope

  • locals (Savon::LocalOptions)

    per-request options

Returns:



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/savon/transport/httpi.rb', line 31

def post(url, soap_headers, body, locals)
  http_request = to_httpi_request(url, soap_headers, body, locals)

  log_request(http_request.url, http_request.headers, http_request.body) if log?

  httpi_response = ::HTTPI.post(http_request, @globals[:adapter])
  response = normalize_response(httpi_response)

  log_response(response) if log?
  response
end

#to_httpi_request(url, soap_headers, body, locals) ⇒ HTTPI::Request

Builds a fully-configured HTTPI::Request.

Parameters:

  • url (String)

    the SOAP endpoint URL

  • soap_headers (Hash)

    SOAP-level headers

  • body (String)

    the serialized SOAP envelope

  • locals (Savon::LocalOptions)

    per-request options

Returns:

  • (HTTPI::Request)


58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/savon/transport/httpi.rb', line 58

def to_httpi_request(url, soap_headers, body, locals)
  headers = {}
  headers.merge!(@globals[:headers]) if @globals.include?(:headers)
  headers.merge!(locals[:headers])   if locals.include?(:headers)

  # soap_headers are lowest priority
  soap_headers.each do |k, v| headers[k] ||= v end

  http_request = ::HTTPI::Request.new
  http_request.url = url
  http_request.body = body
  http_request.headers = headers
  http_request.set_cookies(locals[:cookies]) if locals[:cookies]
  configure_http_request(http_request)
  http_request
end

#wsdl_requestHTTPI::Request

Returns a configured HTTPI::Request for Wasabi's WSDL resolver. Applies global headers and all transport-level options and leaves the rest to Wasabi.

Returns:

  • (HTTPI::Request)


80
81
82
83
84
85
# File 'lib/savon/transport/httpi.rb', line 80

def wsdl_request
  http_request = ::HTTPI::Request.new
  http_request.headers = @globals[:headers].dup if @globals.include?(:headers)
  configure_http_request(http_request)
  http_request
end