Class: Patron::Session

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

Instance Method Summary collapse

Instance Method Details

#orig_requestObject



6
# File 'lib/httplog/adapters/patron.rb', line 6

alias orig_request request

#request(action_name, url, headers, options = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/httplog/adapters/patron.rb', line 7

def request(action_name, url, headers, options = {})
  log_enabled = HttpLog.url_approved?(url)

  if log_enabled
    HttpLog.log_request(action_name, url)
    HttpLog.log_headers(headers)
    HttpLog.log_data(options[:data]) # if action_name == :post
  end

  bm = Benchmark.realtime do
    @response = orig_request(action_name, url, headers, options)
  end

  if log_enabled
    headers = @response.headers
    HttpLog.log_compact(action_name, url, @response.status, bm)
    HttpLog.log_status(@response.status)
    HttpLog.log_benchmark(bm)
    HttpLog.log_headers(headers)
    HttpLog.log_body(@response.body, headers['Content-Encoding'], headers['Content-Type'])
  end

  @response
end