Class: RequestFormatter
- Inherits:
-
Object
- Object
- RequestFormatter
- Defined in:
- lib/see_your_requests/request_formatter.rb
Instance Method Summary collapse
-
#initialize(request) ⇒ RequestFormatter
constructor
A new instance of RequestFormatter.
- #print_body ⇒ Object
- #print_http_headers ⇒ Object
- #print_method ⇒ Object
- #print_request ⇒ Object
Constructor Details
#initialize(request) ⇒ RequestFormatter
Returns a new instance of RequestFormatter.
2 3 4 |
# File 'lib/see_your_requests/request_formatter.rb', line 2 def initialize(request) @request = request end |
Instance Method Details
#print_body ⇒ Object
31 32 33 34 35 36 |
# File 'lib/see_your_requests/request_formatter.rb', line 31 def print_body if @request.body.size > 0 puts 'Request body:' puts @request.body.read end end |
#print_http_headers ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 |
# File 'lib/see_your_requests/request_formatter.rb', line 18 def print_http_headers formatted_headers = {} http_headers = @request.env.select { |k, v| k =~ /^HTTP_.*/ } puts 'HTTP Headers:' http_headers.each do |k, v| formatted_header = k.gsub(/^HTTP_/, "") formatted_headers[formatted_header] = v puts "\t#{ formatted_header }: #{ v }" end formatted_headers.to_s end |
#print_method ⇒ Object
13 14 15 16 |
# File 'lib/see_your_requests/request_formatter.rb', line 13 def print_method method = @request.env["REQUEST_METHOD"] puts "Request method: #{ method }" end |
#print_request ⇒ Object
6 7 8 9 10 11 |
# File 'lib/see_your_requests/request_formatter.rb', line 6 def print_request puts "\nRequest received at #{ Time.now }" print_method print_http_headers print_body end |