From c8bc61469433be6ca2fee9158d73e91a01bd4404 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Mon, 30 Oct 2023 17:59:29 +0900 Subject: [PATCH] Support pretty_print --- lib/net/http/generic_request.rb | 24 ++++++++++++++++++++++++ 1 file changed, 24 insertions(+) diff --git a/lib/net/http/generic_request.rb b/lib/net/http/generic_request.rb index 44e329a0..6d520886 100644 --- a/lib/net/http/generic_request.rb +++ b/lib/net/http/generic_request.rb @@ -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 + # # => # + # ["gzip;q=1.0,deflate;q=0.6,identity;q=0.3"], + # "accept"=>["*/*"], + # "user-agent"=>["Ruby"]}> + # Net::HTTP::Post.new(uri).inspect # => "#" + # + 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.