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
44 45 46 47 48 |
# File 'lib/httplog/adapters/net_http.rb', line 44 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 35 36 37 38 39 40 41 42 |
# File 'lib/httplog/adapters/net_http.rb', line 8 def request(req, body = nil, &block) url = "http://#{@address}:#{@port}#{req.path}" bm = Benchmark.realtime do @response = orig_request(req, body, &block) end body_stream = req.body_stream request_body = if body_stream body_stream.to_s # read and rewind for RestClient::Payload::Base body_stream.rewind if body_stream.respond_to?(:rewind) # RestClient::Payload::Base has no method rewind body_stream.read elsif req.body.nil? || req.body.empty? body else req.body end if HttpLog.url_approved?(url) && started? HttpLog.call( method: req.method, url: url, request_body: request_body, request_headers: req.each_header.collect, response_code: @response.code, response_body: @response.body, response_headers: @response.each_header.collect, benchmark: bm, encoding: @response['Content-Encoding'], content_type: @response['Content-Type'], mask_body: HttpLog.masked_body_url?(url) ) end @response end |