Class: Relax2::Interceptors::PrintResponse
- Inherits:
-
Object
- Object
- Relax2::Interceptors::PrintResponse
- Defined in:
- lib/relax2/interceptors.rb
Instance Method Summary collapse
- #call(request, perform_request) ⇒ Object
-
#initialize(print_status:, print_headers:) ⇒ PrintResponse
constructor
A new instance of PrintResponse.
Constructor Details
#initialize(print_status:, print_headers:) ⇒ PrintResponse
Returns a new instance of PrintResponse.
33 34 35 36 |
# File 'lib/relax2/interceptors.rb', line 33 def initialize(print_status:, print_headers:) @print_status = print_status @print_headers = print_headers end |
Instance Method Details
#call(request, perform_request) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/relax2/interceptors.rb', line 38 def call(request, perform_request) lines = [] response = perform_request.call(request) lines << "HTTP #{response.status}" if @print_status if @print_headers response.headers.each do |name, value| lines << "#{name}: #{value}" end end if response.body lines << '' unless lines.empty? lines << response.body end puts lines.join("\n") end |