Module: Ethon::Easy::Operations
- Defined in:
- lib/httplog/adapters/ethon.rb
Instance Method Summary collapse
Instance Method Details
#orig_perform ⇒ Object
23 |
# File 'lib/httplog/adapters/ethon.rb', line 23 alias orig_perform perform |
#perform ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/httplog/adapters/ethon.rb', line 24 def perform return orig_perform unless HttpLog.url_approved?(url) bm = Benchmark.realtime { orig_perform } # Not sure where the actual status code is stored - so let's # extract it from the response header. status = response_headers.scan(%r{HTTP/... (\d{3})}).flatten.first encoding = response_headers.scan(/Content-Encoding: (\S+)/).flatten.first content_type = response_headers.scan(/Content-Type: (\S+(; charset=\S+)?)/).flatten.first # Hard to believe that Ethon wouldn't parse out the headers into # an array; probably overlooked it. Anyway, let's do it ourselves: headers = response_headers.split(/\r?\n/)[1..-1] HttpLog.log_compact(@action_name, @url, @return_code, bm) HttpLog.log_status(status) HttpLog.log_benchmark(bm) HttpLog.log_headers(headers) HttpLog.log_body(response_body, encoding, content_type) return_code end |