Around HTTP Request Hook
The around_http_request
hook wraps each HTTP request. It can be used rather than separate before_http_request
and after_http_request
hooks to simplify wrapping/transactional logic (such as using a VCR cassette).
In your block, call #proceed
on the yielded request to cause it to continue. Alternately, you can treat the request as a proc and pass it on to a method that expects a block by prefixing it with an ampersand (&request
).
Note that around_http_request
will not work on Ruby 1.8. It uses a fiber under the covers and thus is only available on interpreters that support fibers. On 1.8, you can use separate before_http_request
and after_http_request
hooks.
globally handle requests using an around_http_request hook
Given a file named "globally_handle_requests.rb" with:
When I run ruby globally_handle_requests.rb
Then it should pass with:
And the file "cassettes/global.yml" should contain "Response 1".
Examples
Last updated