Skip to content

Commit

Permalink
ez-inspectation
Browse files Browse the repository at this point in the history
  • Loading branch information
0exp committed Jun 18, 2024
1 parent 3221ad6 commit 955af5e
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 3 deletions.
2 changes: 1 addition & 1 deletion lib/ezclient/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def initialize(verb, url, options)
def perform
http_response = perform_request

EzClient::Response.new(http_response).tap do |response|
EzClient::Response.new(http_response, http_request).tap do |response|
on_complete.call(self, response, options[:metadata])
end
rescue => error
Expand Down
23 changes: 21 additions & 2 deletions lib/ezclient/response.rb
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
# frozen_string_literal: true

class EzClient::Response
attr_accessor :http_response, :body
attr_accessor :http_response, :body, :http_request

def initialize(http_response)
def initialize(http_response, http_request)
self.http_response = http_response
self.http_request = http_request
self.body = http_response.body.to_s # Make sure we read the body for persistent connection
end

Expand Down Expand Up @@ -40,4 +41,22 @@ def server_error?
def error?
client_error? || server_error?
end

def inspect
{
request: {
raw: http_request.inspect,
headers: http_request.headers
},
response: {
raw: http_response.inspect,
headers:,
body:
}
}.to_s
end

def to_s
inspect
end
end

0 comments on commit 955af5e

Please sign in to comment.