Class: HTTParty::ConnectionAdapter
- Inherits:
-
Object
- Object
- HTTParty::ConnectionAdapter
- Defined in:
- lib/httparty/connection_adapter.rb
Overview
Default connection adapter that returns a new Net::HTTP each time
Custom Connection Factories
If you like to implement your own connection adapter, subclassing HTTPParty::ConnectionAdapter will make it easier. Just override the #connection method. The uri and options attributes will have all the info you need to construct your http connection. Whatever you return from your connection method needs to adhere to the Net::HTTP interface as this is what HTTParty expects.
Configuration
There is lots of configuration data available for your connection adapter in the #options attribute. It is up to you to interpret them within your connection adapter. Take a look at the implementation of HTTParty::ConnectionAdapter#connection for examples of how they are used. Something are probably interesting are as follows:
-
:timeout: timeout in seconds
-
:debug_output: see HTTParty::ClassMethods.debug_output.
-
:pem: contains pem data. see HTTParty::ClassMethods.pem.
-
:ssl_ca_file: see HTTParty::ClassMethods.ssl_ca_file.
-
:ssl_ca_path: see HTTParty::ClassMethods.ssl_ca_path.
-
:connection_adapter_options: contains the hash your passed to HTTParty.connection_adapter when you configured your connection adapter
Constant Summary
- StripIpv6BracketsRegex =
Private: Regex used to strip brackets from IPv6 URIs.
/\A\[(.*)\]\z/
Instance Attribute Summary (collapse)
-
- (Object) options
readonly
Returns the value of attribute options.
-
- (Object) uri
readonly
Returns the value of attribute uri.
Class Method Summary (collapse)
-
+ (Object) call(uri, options)
Public.
Instance Method Summary (collapse)
- - (Object) connection
-
- (ConnectionAdapter) initialize(uri, options = {})
constructor
A new instance of ConnectionAdapter.
Constructor Details
- (ConnectionAdapter) initialize(uri, options = {})
A new instance of ConnectionAdapter
60 61 62 63 64 65 |
# File 'lib/httparty/connection_adapter.rb', line 60 def initialize(uri, ={}) raise ArgumentError, "uri must be a URI, not a #{uri.class}" unless uri.kind_of? URI @uri = uri @options = end |
Instance Attribute Details
- (Object) options (readonly)
Returns the value of attribute options
58 59 60 |
# File 'lib/httparty/connection_adapter.rb', line 58 def @options end |
- (Object) uri (readonly)
Returns the value of attribute uri
58 59 60 |
# File 'lib/httparty/connection_adapter.rb', line 58 def uri @uri end |
Class Method Details
+ (Object) call(uri, options)
Public
54 55 56 |
# File 'lib/httparty/connection_adapter.rb', line 54 def self.call(uri, ) new(uri, ).connection end |
Instance Method Details
- (Object) connection
67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/httparty/connection_adapter.rb', line 67 def connection host = clean_host(uri.host) http = Net::HTTP.new(host, uri.port, [:http_proxyaddr], [:http_proxyport], [:http_proxyuser], [:http_proxypass]) http.use_ssl = ssl_implied?(uri) attach_ssl_certificates(http, ) if [:timeout] && ([:timeout].is_a?(Integer) || [:timeout].is_a?(Float)) http.open_timeout = [:timeout] http.read_timeout = [:timeout] end if [:debug_output] http.set_debug_output([:debug_output]) end if [:ciphers] http.ciphers = [:ciphers] end return http end |