Skip to content

Commit cef3926

Browse files
committed
Instrument request.active_resource with Net::HTTPRequest instance
This commit exposes the underlying [Net::HTTPRequest][] instance to the published `request.active_resource` Active Support notification payload. [rails#449]: rails#449 [Net::HTTPRequest]: https://docs.ruby-lang.org/en/master/Net/HTTPRequest.html
1 parent b2ad3bd commit cef3926

File tree

3 files changed

+5
-1
lines changed

3 files changed

+5
-1
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -342,11 +342,12 @@ ActiveSupport::Notifications.subscribe('request.active_resource') do |name, sta
342342

343343
The `payload` is a `Hash` with the following keys:
344344

345+
* `request` as a [Net::HTTPRequest](https://docs.ruby-lang.org/en/master/Net/HTTPRequest.html)
345346
* `method` as a `Symbol`
346347
* `request_uri` as a `String`
347348
* `headers` as a `Hash`
348349
* `body` as a `String` when available
349-
* `result` as an `Net::HTTPResponse`
350+
* `result` as a [Net::HTTPResponse](https://docs.ruby-lang.org/en/master/Net/HTTPResponse.html)
350351

351352
## License
352353

lib/active_resource/connection.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,7 @@ def request(method, path, *arguments)
133133
payload[:request_uri] = request.uri.to_s
134134
payload[:headers] = request.each_capitalized.to_h
135135
payload[:body] = body
136+
payload[:request] = request
136137
payload[:result] = http.request(request)
137138
end
138139
handle_response(result)

test/cases/notifications_test.rb

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ def test_get_request_with_params
2121
assert_equal "http://37s.sunrise.i:3000/people.json?name=Matz", payload[:request_uri]
2222
assert_equal({ "Accept" => "application/json" }, payload[:headers])
2323
assert_nil payload[:body]
24+
assert_kind_of Net::HTTP::Get, payload[:request]
2425
assert_kind_of ActiveResource::Response, payload[:result]
2526
end
2627

@@ -31,6 +32,7 @@ def test_post_request_with_body
3132
assert_equal "http://37s.sunrise.i:3000/people.json", payload[:request_uri]
3233
assert_equal({ "Content-Type" => "application/json" }, payload[:headers])
3334
assert_equal({ "person" => { "name" => "Matz" } }.to_json, payload[:body])
35+
assert_kind_of Net::HTTP::Post, payload[:request]
3436
assert_kind_of ActiveResource::Response, payload[:result]
3537
end
3638

0 commit comments

Comments
 (0)