Class: Zotero::HTTPConnection
- Inherits:
-
Object
- Object
- Zotero::HTTPConnection
- Defined in:
- lib/zotero/http_connection.rb
Overview
Manages HTTP connections with proper SSL configuration and timeouts
Constant Summary collapse
- DEFAULT_OPEN_TIMEOUT =
30- DEFAULT_READ_TIMEOUT =
60
Instance Attribute Summary collapse
-
#config ⇒ Object
readonly
private
Returns the value of attribute config.
-
#http ⇒ Object
readonly
private
Returns the value of attribute http.
-
#uri ⇒ Object
readonly
private
Returns the value of attribute uri.
Instance Method Summary collapse
- #build_connection ⇒ Object private
- #configure_connection ⇒ Object private
- #configure_ssl ⇒ Object private
- #configure_timeouts ⇒ Object private
-
#initialize(uri, config = nil) ⇒ HTTPConnection
constructor
A new instance of HTTPConnection.
- #request(net_request) ⇒ Object
Constructor Details
#initialize(uri, config = nil) ⇒ HTTPConnection
Returns a new instance of HTTPConnection.
12 13 14 15 16 |
# File 'lib/zotero/http_connection.rb', line 12 def initialize(uri, config = nil) @uri = uri @config = config || HTTPConfig.default @http = build_connection end |
Instance Attribute Details
#config ⇒ Object (readonly, private)
Returns the value of attribute config.
25 26 27 |
# File 'lib/zotero/http_connection.rb', line 25 def config @config end |
#http ⇒ Object (readonly, private)
Returns the value of attribute http.
25 26 27 |
# File 'lib/zotero/http_connection.rb', line 25 def http @http end |
#uri ⇒ Object (readonly, private)
Returns the value of attribute uri.
25 26 27 |
# File 'lib/zotero/http_connection.rb', line 25 def uri @uri end |
Instance Method Details
#build_connection ⇒ Object (private)
27 28 29 |
# File 'lib/zotero/http_connection.rb', line 27 def build_connection Net::HTTP.new(@uri.host, @uri.port) end |
#configure_connection ⇒ Object (private)
31 32 33 34 35 |
# File 'lib/zotero/http_connection.rb', line 31 def configure_connection configure_ssl if @uri.scheme == "https" configure_timeouts @configured = true end |
#configure_ssl ⇒ Object (private)
37 38 39 40 41 |
# File 'lib/zotero/http_connection.rb', line 37 def configure_ssl @http.use_ssl = true @http.verify_mode = OpenSSL::SSL::VERIFY_PEER @http.ca_file = OpenSSL::X509::DEFAULT_CERT_FILE end |
#configure_timeouts ⇒ Object (private)
43 44 45 46 |
# File 'lib/zotero/http_connection.rb', line 43 def configure_timeouts @http.open_timeout = @config.open_timeout @http.read_timeout = @config.read_timeout end |
#request(net_request) ⇒ Object
18 19 20 21 |
# File 'lib/zotero/http_connection.rb', line 18 def request(net_request) configure_connection unless @configured @http.request(net_request) end |