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
31
# File 'lib/httplog/adapters/patron.rb', line 7

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

  if HttpLog.url_approved?(url)
    normalized_headers = @response.headers.transform_keys(&:downcase)

    HttpLog.call(
      method: action_name,
      url: url,
      request_body: options[:data],
      request_headers: headers,
      response_code: @response.status,
      response_body: @response.body,
      response_headers: normalized_headers,
      benchmark: bm,
      encoding: normalized_headers['content-encoding'],
      content_type: normalized_headers['content-type'],
      mask_body: HttpLog.masked_body_url?(url)
    )
  end

  @response
end