Skip to content

Commit

Permalink
Support pretty_print
Browse files Browse the repository at this point in the history
  • Loading branch information
nobu committed Oct 30, 2023
1 parent 97be4de commit c8bc614
Showing 1 changed file with 24 additions and 0 deletions.
24 changes: 24 additions & 0 deletions lib/net/http/generic_request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,30 @@ def inspect
"\#<#{self.class} #{@method}>"
end

# Returns a string representation of the request with the details for pp:
#
# require 'pp'
# Net::HTTP::Post.new(uri).pretty_inspect
# # => #<Net::HTTP::Get
# GET
# path="/"
# headers={"accept-encoding"=>
# ["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],
# "accept"=>["*/*"],
# "user-agent"=>["Ruby"]}>
# Net::HTTP::Post.new(uri).inspect # => "#<Net::HTTP::Post POST>"
#
def pretty_print(q)
q.object_group(self) {
q.breakable
q.text @method
q.breakable
q.text "path="; q.pp @path
q.breakable
q.text "headers="; q.pp to_hash
}
end

##
# Don't automatically decode response content-encoding if the user indicates
# they want to handle it.
Expand Down

0 comments on commit c8bc614

Please sign in to comment.