Class: Net::HTTP
- Inherits:
-
Object
- Object
- Net::HTTP
- Defined in:
- lib/httplog/adapters/net_http.rb
Instance Method Summary collapse
- #connect ⇒ Object
- #orig_connect ⇒ Object
- #orig_request ⇒ Object
- #request(req, body = nil, &block) ⇒ Object
Instance Method Details
#connect ⇒ Object
36 37 38 39 40 |
# File 'lib/httplog/adapters/net_http.rb', line 36 def connect HttpLog.log_connection(@address, @port) if !started? && HttpLog.url_approved?("#{@address}:#{@port}") orig_connect end |
#orig_connect ⇒ Object
6 |
# File 'lib/httplog/adapters/net_http.rb', line 6 alias orig_connect connect |
#orig_request ⇒ Object
5 |
# File 'lib/httplog/adapters/net_http.rb', line 5 alias orig_request request |
#request(req, body = nil, &block) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/httplog/adapters/net_http.rb', line 8 def request(req, body = nil, &block) url = "http://#{@address}:#{@port}#{req.path}" log_enabled = HttpLog.url_approved?(url) if log_enabled && started? HttpLog.log_request(req.method, url) HttpLog.log_headers(req.each_header.collect) # A bit convoluted becase post_form uses form_data= to assign the data, so # in that case req.body will be empty. HttpLog.log_data(req.body.nil? || req.body.empty? ? body : req.body) # if req.method == 'POST' end bm = Benchmark.realtime do @response = orig_request(req, body, &block) end if log_enabled && started? HttpLog.log_compact(req.method, url, @response.code, bm) HttpLog.log_status(@response.code) HttpLog.log_benchmark(bm) HttpLog.log_headers(@response.each_header.collect) HttpLog.log_body(@response.body, @response['Content-Encoding'], @response['Content-Type']) end @response end |