Class: Net::HTTP

Inherits:
Object
  • Object
show all
Defined in:
lib/http/ext/net_http.rb

Instance Method Summary collapse

Instance Method Details

#request_with_wiretap(request, body = nil, &block) ⇒ Object Also known as: request



6
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
32
33
# File 'lib/http/ext/net_http.rb', line 6

def request_with_wiretap(request, body = nil, &block)
  request_id = nil
  
  # Log request
  if ::HTTP::Wiretap.enabled
    request_id = ::HTTP::Wiretap.log_request(self, request)
  end
  
  # Send request
  block_response = nil
  block_wrapper = lambda do |res|
    puts "inside: #{res}"
    block_response = res
    block.call(res) unless block.nil?
    res
  end
  return_response = request_without_wiretap(request, body, &block_wrapper)
  
  # Use whichever 
  response = nil
  response = return_response if return_response.is_a?(Net::HTTPResponse)
  response = block_response if response.nil?

  # Log response
  if ::HTTP::Wiretap.enabled
    ::HTTP::Wiretap.log_response(self, response, request_id)
  end
end