Skip to content

Commit bfc6045

Browse files
committed
Support pretty_print
1 parent d81eabf commit bfc6045

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

lib/net/http/generic_request.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,31 @@ 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+
# post = Net::HTTP::Post.new(uri)
109+
# post.inspect # => "#<Net::HTTP::Post POST>"
110+
# post.pretty_inspect
111+
# # => #<Net::HTTP::Post
112+
# POST
113+
# path="/"
114+
# headers={"accept-encoding" => ["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],
115+
# "accept" => ["*/*"],
116+
# "user-agent" => ["Ruby"],
117+
# "host" => ["www.ruby-lang.org"]}>
118+
#
119+
def pretty_print(q)
120+
q.object_group(self) {
121+
q.breakable
122+
q.text @method
123+
q.breakable
124+
q.text "path="; q.pp @path
125+
q.breakable
126+
q.text "headers="; q.pp to_hash
127+
}
128+
end
129+
105130
##
106131
# Don't automatically decode response content-encoding if the user indicates
107132
# they want to handle it.

0 commit comments

Comments
 (0)