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

#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
42
# 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?

  http_response = ::HTTPI.post(http_request, @globals[:adapter])
  response = Response.from_httpi(http_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)


51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
# File 'lib/savon/transport/httpi.rb', line 51

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

  if locals[:cookies]&.any?
    headers["Cookie"] = locals[:cookies].map(&:name_and_value).join(";")
  end

  headers["Content-Length"] = body.bytesize.to_s

  http_request = ::HTTPI::Request.new
  http_request.url = url
  http_request.body = body
  http_request.headers = headers
  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)


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

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