Class: Logglier::Client::HTTP::NetHTTPProxy
- Inherits:
-
Object
- Object
- Logglier::Client::HTTP::NetHTTPProxy
- Defined in:
- lib/logglier/client/http/sync.rb
Overview
Used to wrap and setup Net::HTTP as we need it
Constant Summary collapse
- RETRY_EXCEPTIONS =
[ Timeout::Error, OpenSSL::SSL::SSLError, Errno::EPIPE, EOFError, Errno::ECONNRESET, Errno::ETIMEDOUT, Errno::ECONNREFUSED ]
- RETRIES =
3
Instance Attribute Summary collapse
-
#failsafe ⇒ Object
Returns the value of attribute failsafe.
Instance Method Summary collapse
-
#deliver(message) ⇒ Object
Delivers the message via HTTP, handling errors.
-
#initialize(input_uri, opts = {}) ⇒ NetHTTPProxy
constructor
A new instance of NetHTTPProxy.
Constructor Details
#initialize(input_uri, opts = {}) ⇒ NetHTTPProxy
Returns a new instance of NetHTTPProxy.
27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/logglier/client/http/sync.rb', line 27 def initialize(input_uri, opts={}) @input_uri = input_uri @verify_mode = opts[:verify_mode] || OpenSSL::SSL::VERIFY_PEER @ca_file = opts[:ca_file] @read_timeout = opts[:read_timeout] || 5 @open_timeout = opts[:open_timeout] || 5 @failsafe = opts[:failsafe] || $stderr @format = opts[:format] ? opts[:format].to_sym : nil @proxy_addr = opts[:proxy_addr] @proxy_port = opts[:proxy_port] @proxy_user = opts[:proxy_user] @proxy_password = opts[:proxy_password] @headers = {} if @format == :json @headers['Content-Type'] = 'application/json' else @headers['Content-Type'] = 'text/plain' end @http = nil end |
Instance Attribute Details
#failsafe ⇒ Object
Returns the value of attribute failsafe.
18 19 20 |
# File 'lib/logglier/client/http/sync.rb', line 18 def failsafe @failsafe end |
Instance Method Details
#deliver(message) ⇒ Object
Delivers the message via HTTP, handling errors
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/logglier/client/http/sync.rb', line 51 def deliver() retries = 0 begin if @http.nil? connect! end @http.request_post(@input_uri.path, , @headers) rescue *RETRY_EXCEPTIONS => e @http = nil if retries < RETRIES retries += 1 (e, , retries) sleep(retries) retry else failsafe_errored(e, ) end rescue Exception => e @http = nil failsafe_errored(e, ) end end |