Skip to content

Commit c8bc614

Browse files
committed
Support pretty_print
1 parent 97be4de commit c8bc614

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

lib/net/http/generic_request.rb

+24
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,30 @@ def inspect
102102
"\#<#{self.class} #{@method}>"
103103
end
104104

105+
# Returns a string representation of the request with the details for pp:
106+
#
107+
# require 'pp'
108+
# Net::HTTP::Post.new(uri).pretty_inspect
109+
# # => #<Net::HTTP::Get
110+
# GET
111+
# path="/"
112+
# headers={"accept-encoding"=>
113+
# ["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],
114+
# "accept"=>["*/*"],
115+
# "user-agent"=>["Ruby"]}>
116+
# Net::HTTP::Post.new(uri).inspect # => "#<Net::HTTP::Post POST>"
117+
#
118+
def pretty_print(q)
119+
q.object_group(self) {
120+
q.breakable
121+
q.text @method
122+
q.breakable
123+
q.text "path="; q.pp @path
124+
q.breakable
125+
q.text "headers="; q.pp to_hash
126+
}
127+
end
128+
105129
##
106130
# Don't automatically decode response content-encoding if the user indicates
107131
# they want to handle it.

0 commit comments

Comments
 (0)