summaryrefslogtreecommitdiff
path: root/lib
diff options
context:
space:
mode:
authorNobuyoshi Nakada <[email protected]>2023-10-30 17:59:29 +0900
committergit <[email protected]>2025-06-11 05:04:16 +0000
commit51118fa2da6267d71915d0614cae733b94782f7f (patch)
tree0799d295b7bc96fe17b2c5c7791ca1477664acbc /lib
parenta976fa1bb7e04d5484e2992ba42d03312109d0ee (diff)
[ruby/net-http] Support pretty_print
https://github.com/ruby/net-http/commit/bfc60454f6
Diffstat (limited to 'lib')
-rw-r--r--lib/net/http/generic_request.rb25
1 files changed, 25 insertions, 0 deletions
diff --git a/lib/net/http/generic_request.rb b/lib/net/http/generic_request.rb
index 0e66c2d69b..c92004e557 100644
--- a/lib/net/http/generic_request.rb
+++ b/lib/net/http/generic_request.rb
@@ -102,6 +102,31 @@ class Net::HTTPGenericRequest
"\#<#{self.class} #{@method}>"
end
+ # Returns a string representation of the request with the details for pp:
+ #
+ # require 'pp'
+ # post = Net::HTTP::Post.new(uri)
+ # post.inspect # => "#<Net::HTTP::Post POST>"
+ # post.pretty_inspect
+ # # => #<Net::HTTP::Post
+ # POST
+ # path="/"
+ # headers={"accept-encoding" => ["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"],
+ # "accept" => ["*/*"],
+ # "user-agent" => ["Ruby"],
+ # "host" => ["www.ruby-lang.org"]}>
+ #
+ 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.