From b82fa4ad34011ed0dab8d7aae25bc9e5bfac9ee3 Mon Sep 17 00:00:00 2001 From: HU Hailin Date: Fri, 10 Mar 2023 16:03:04 +0900 Subject: [PATCH] make request body available for logging --- README.md | 1 + lib/active_resource/connection.rb | 7 ++++--- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index fefaf4e943..9c8e3024ed 100644 --- a/README.md +++ b/README.md @@ -296,6 +296,7 @@ The `payload` is a `Hash` with the following keys: * `method` as a `Symbol` * `request_uri` as a `String` +* `request_body` as a `String` * `result` as an `Net::HTTPResponse` ## License diff --git a/lib/active_resource/connection.rb b/lib/active_resource/connection.rb index e997a0a2f6..91b4bbc078 100644 --- a/lib/active_resource/connection.rb +++ b/lib/active_resource/connection.rb @@ -118,9 +118,10 @@ def head(path, headers = {}) # Makes a request to the remote service. def request(method, path, *arguments) result = ActiveSupport::Notifications.instrument("request.active_resource") do |payload| - payload[:method] = method - payload[:request_uri] = "#{site.scheme}://#{site.host}:#{site.port}#{path}" - payload[:result] = http.send(method, path, *arguments) + payload[:method] = method + payload[:request_uri] = "#{site.scheme}://#{site.host}:#{site.port}#{path}" + payload[:request_body] = arguments[0] if Object.const_get("Net::HTTP::#{method.capitalize}::REQUEST_HAS_BODY") + payload[:result] = http.send(method, path, *arguments) end handle_response(result) rescue Timeout::Error => e