Module: Savon::HTTPITransportOptions

Included in:
GlobalOptions
Defined in:
lib/savon/options.rb

Overview

HTTPI-specific transport options included in GlobalOptions.

Every option in this module is handled by HTTPI and has no effect when transport: :faraday is set. Faraday callers configure these concerns directly on the Faraday::Connection returned by client.faraday.

Constant Summary collapse

FARADAY_INCOMPATIBLE_GLOBALS =

Maps each httpi-only option to the Faraday equivalent so the error raised at init tells the caller exactly what to do instead. Options with a :default entry are only flagged when the caller sets a value that differs from the GlobalOptions default.

{
  proxy: { hint: "client.faraday.proxy = url" },
  open_timeout: { hint: "client.faraday.options.timeout = N" },
  read_timeout: { hint: "client.faraday.options.timeout = N" },
  write_timeout: { hint: "client.faraday.options.write_timeout = N" },
  ssl_version: { hint: "client.faraday.ssl.version = version" },
  ssl_min_version: { hint: "client.faraday.ssl.min_version = version" },
  ssl_max_version: { hint: "client.faraday.ssl.max_version = version" },
  ssl_verify_mode: { hint: "client.faraday.ssl.verify = true/false" },
  ssl_cert_key_file: { hint: "client.faraday.ssl.client_key_file = path" },
  ssl_cert_key: { hint: "client.faraday.ssl.client_key = key" },
  ssl_cert_key_password: { hint: "configure ssl context on client.faraday.ssl" },
  ssl_cert_file: { hint: "client.faraday.ssl.client_cert_file = path" },
  ssl_cert: { hint: "client.faraday.ssl.client_cert = cert" },
  ssl_ca_cert_file: { hint: "client.faraday.ssl.ca_file = path" },
  ssl_ca_cert: { hint: "client.faraday.ssl.ca_cert = cert" },
  ssl_ciphers: { hint: "client.faraday.ssl.ciphers = ciphers" },
  ssl_ca_cert_path: { hint: "client.faraday.ssl.ca_path = path" },
  ssl_cert_store: { hint: "client.faraday.ssl.cert_store = store" },
  basic_auth: { hint: "client.faraday.request :basic_auth, user, pass" },
  digest_auth: { hint: "client.faraday.request :authorization, :Digest, credentials" },
  ntlm: { hint: "client.faraday.request :ntlm, user, pass" },
  follow_redirects: { hint: "client.faraday.use :follow_redirects", default: false },
  adapter: { hint: "client.faraday.adapter :net_http", default: nil }
}.freeze

Instance Method Summary collapse

Instance Method Details

#adapter(adapter) ⇒ Object

Instruct Savon which HTTPI adapter to use instead of the default.



249
250
251
# File 'lib/savon/options.rb', line 249

def adapter(adapter)
  @options[:adapter] = adapter
end

#basic_auth(*credentials) ⇒ Object

HTTP basic auth credentials.



229
230
231
# File 'lib/savon/options.rb', line 229

def basic_auth(*credentials)
  @options[:basic_auth] = credentials.flatten
end

#digest_auth(*credentials) ⇒ Object

HTTP digest auth credentials.



234
235
236
# File 'lib/savon/options.rb', line 234

def digest_auth(*credentials)
  @options[:digest_auth] = credentials.flatten
end

#follow_redirects(follow_redirects) ⇒ Object

Instruct requests to follow HTTP redirects.



244
245
246
# File 'lib/savon/options.rb', line 244

def follow_redirects(follow_redirects)
  @options[:follow_redirects] = follow_redirects
end

#ntlm(*credentials) ⇒ Object

NTLM auth credentials.



239
240
241
# File 'lib/savon/options.rb', line 239

def ntlm(*credentials)
  @options[:ntlm] = credentials.flatten
end

#open_timeout(open_timeout) ⇒ Object

Open timeout in seconds.



144
145
146
# File 'lib/savon/options.rb', line 144

def open_timeout(open_timeout)
  @options[:open_timeout] = open_timeout
end

#proxy(proxy) ⇒ Object

Proxy server to use for all requests.



139
140
141
# File 'lib/savon/options.rb', line 139

def proxy(proxy)
  @options[:proxy] = proxy unless proxy.nil?
end

#read_timeout(read_timeout) ⇒ Object

Read timeout in seconds.



149
150
151
# File 'lib/savon/options.rb', line 149

def read_timeout(read_timeout)
  @options[:read_timeout] = read_timeout
end

#ssl_ca_cert(cert) ⇒ Object

Sets the CA cert to use.



209
210
211
# File 'lib/savon/options.rb', line 209

def ssl_ca_cert(cert)
  @options[:ssl_ca_cert] = cert
end

#ssl_ca_cert_file(file) ⇒ Object

Sets the CA cert file to use.



204
205
206
# File 'lib/savon/options.rb', line 204

def ssl_ca_cert_file(file)
  @options[:ssl_ca_cert_file] = file
end

#ssl_ca_cert_path(path) ⇒ Object

Sets the CA cert path.



219
220
221
# File 'lib/savon/options.rb', line 219

def ssl_ca_cert_path(path)
  @options[:ssl_ca_cert_path] = path
end

#ssl_cert(cert) ⇒ Object

Sets the cert to use.



199
200
201
# File 'lib/savon/options.rb', line 199

def ssl_cert(cert)
  @options[:ssl_cert] = cert
end

#ssl_cert_file(file) ⇒ Object

Sets the cert file to use.



194
195
196
# File 'lib/savon/options.rb', line 194

def ssl_cert_file(file)
  @options[:ssl_cert_file] = file
end

#ssl_cert_key(key) ⇒ Object

Sets the cert key to use.



184
185
186
# File 'lib/savon/options.rb', line 184

def ssl_cert_key(key)
  @options[:ssl_cert_key] = key
end

#ssl_cert_key_file(file) ⇒ Object

Sets the cert key file to use.



179
180
181
# File 'lib/savon/options.rb', line 179

def ssl_cert_key_file(file)
  @options[:ssl_cert_key_file] = file
end

#ssl_cert_key_password(password) ⇒ Object

Sets the cert key password to use.



189
190
191
# File 'lib/savon/options.rb', line 189

def ssl_cert_key_password(password)
  @options[:ssl_cert_key_password] = password
end

#ssl_cert_store(store) ⇒ Object

Sets the SSL cert store.



224
225
226
# File 'lib/savon/options.rb', line 224

def ssl_cert_store(store)
  @options[:ssl_cert_store] = store
end

#ssl_ciphers(ciphers) ⇒ Object

Sets the SSL ciphers to use.



214
215
216
# File 'lib/savon/options.rb', line 214

def ssl_ciphers(ciphers)
  @options[:ssl_ciphers] = ciphers
end

#ssl_max_version(version) ⇒ Object

Specifies the maximum SSL version to use.



169
170
171
# File 'lib/savon/options.rb', line 169

def ssl_max_version(version)
  @options[:ssl_max_version] = version
end

#ssl_min_version(version) ⇒ Object

Specifies the minimum SSL version to use.



164
165
166
# File 'lib/savon/options.rb', line 164

def ssl_min_version(version)
  @options[:ssl_min_version] = version
end

#ssl_verify_mode(verify_mode) ⇒ Object

Whether and how to verify the SSL connection.



174
175
176
# File 'lib/savon/options.rb', line 174

def ssl_verify_mode(verify_mode)
  @options[:ssl_verify_mode] = verify_mode
end

#ssl_version(version) ⇒ Object

Specifies the SSL version to use.



159
160
161
# File 'lib/savon/options.rb', line 159

def ssl_version(version)
  @options[:ssl_version] = version
end

#validate_transport!Object

Validates that the chosen transport is compatible with the options set. Must be called after all options (including any block-form options) are set. Collects every conflict and raises a single InitializationError listing all problems and solutions at once.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/savon/options.rb', line 116

def validate_transport!
  return unless self[:transport] == :faraday

  unless faraday_loaded?
    raise InitializationError,
          "transport: :faraday requires the faraday gem.\n" \
          "Add to your Gemfile: gem 'faraday'"
  end

  violations = FARADAY_INCOMPATIBLE_GLOBALS.filter_map { |option, config|
    next unless include?(option)
    next if config.key?(:default) && self[option] == config[:default]

    "  #{option} - Use: #{config[:hint]}"
  }

  return if violations.empty?

  raise InitializationError,
        "The following options are not supported with transport: :faraday:\n#{violations.join("\n")}"
end

#write_timeout(write_timeout) ⇒ Object

Write timeout in seconds.



154
155
156
# File 'lib/savon/options.rb', line 154

def write_timeout(write_timeout)
  @options[:write_timeout] = write_timeout
end