Class: Excon::Connection

Inherits:
Object
  • Object
show all
Defined in:
lib/httplog/adapters/excon.rb

Instance Method Summary collapse

Instance Method Details

#_httplog_url(datum) ⇒ Object



16
17
18
# File 'lib/httplog/adapters/excon.rb', line 16

def _httplog_url(datum)
  "#{datum[:scheme]}://#{datum[:host]}:#{datum[:port]}#{datum[:path]}#{datum[:query]}"
end

#orig_requestObject



20
# File 'lib/httplog/adapters/excon.rb', line 20

alias orig_request request

#orig_request_callObject



38
# File 'lib/httplog/adapters/excon.rb', line 38

alias orig_request_call request_call

#orig_responseObject



50
# File 'lib/httplog/adapters/excon.rb', line 50

alias orig_response response

#request(params, &block) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/httplog/adapters/excon.rb', line 21

def request(params, &block)
  result = nil
  bm = Benchmark.realtime do
    result = orig_request(params, &block)
  end

  datum = @data.merge(params)
  datum[:headers] = @data[:headers].merge(datum[:headers] || {})
  url = _httplog_url(datum)

  if HttpLog.url_approved?(url)
    HttpLog.log_compact(datum[:method], url, datum[:status] || result.status, bm)
    HttpLog.log_benchmark(bm)
  end
  result
end

#request_call(datum) ⇒ Object



39
40
41
42
43
44
45
46
47
48
# File 'lib/httplog/adapters/excon.rb', line 39

def request_call(datum)
  url = _httplog_url(datum)

  if HttpLog.url_approved?(url)
    HttpLog.log_request(datum[:method], _httplog_url(datum))
    HttpLog.log_headers(datum[:headers])
    HttpLog.log_data(datum[:body]) # if datum[:method] == :post
  end
  orig_request_call(datum)
end

#response(datum = {}) ⇒ Object



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/httplog/adapters/excon.rb', line 51

def response(datum = {})
  return orig_response(datum) unless HttpLog.url_approved?(_httplog_url(datum))

  datum = orig_response(datum)
  response = datum[:response]
  headers = response[:headers] || {}
  HttpLog.log_status(response[:status])
  HttpLog.log_headers(headers)
  HttpLog.log_body(response[:body], headers['Content-Encoding'], headers['Content-Type'])
  datum
end