Class: Logglier::Client::HTTP::NetHTTPProxy

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(input_uri, opts = {}) ⇒ NetHTTPProxy

Returns a new instance of NetHTTPProxy.

Parameters:

  • input_uri (URI)

    URI to deliver messages to

  • opts (Hash) (defaults to: {})

    Option hash

  • [Integer] (Hash)

    a customizable set of options

  • [String] (Hash)

    a customizable set of options

  • [IO] (Hash)

    a customizable set of options



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

#failsafeObject

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

Parameters:

  • message (String)

    The message to deliver



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(message)
  retries = 0

  begin
    if @http.nil?
      connect!
    end

    @http.request_post(@input_uri.path, message, @headers)
  rescue *RETRY_EXCEPTIONS => e
    @http = nil
    if retries < RETRIES
      retries += 1
      failsafe_retrying(e, message, retries)
      sleep(retries)
      retry
    else
      failsafe_errored(e, message)
    end
  rescue Exception => e
    @http = nil
    failsafe_errored(e, message)
  end
end