Before HTTP Request Hook
The before_http_request
hook gets called with each request just before it proceeds. It can be used for many things:
globally logging requests
inserting a particular cassette based on the request URI host
raising a timeout error
You can also pass one or more "filters" to
before_http_request
, to make the hook only be called for some requests. Any object that responds to#to_proc
can be a filter. Here are some simple examples::real?
-- only real requests:stubbed?
-- only stubbed requests:ignored?
-- only ignored requests:recordable?
-- only requests that are being recordedlambda { |r| URI(r.uri).host == 'amazon.com' }
-- only requests to amazon.com.
log all requests using a before_http_request hook
Given a file named "before_http_request.rb" with:
When I run ruby before_http_request.rb run1.log --with-server
Given that port numbers in "run1.log" are normalized to "7777"
Then the file "run1.log" should contain "before real request: get http://localhost:7777/"
When I run ruby before_http_request.rb run2.log
Then the file "run2.log" should not exist.
Examples
configuration | http_lib |
c.hook_into :webmock | net/http |
c.hook_into :webmock | httpclient |
c.hook_into :webmock | curb |
c.hook_into :typhoeus | typhoeus |
c.hook_into :excon | excon |
c.hook_into :faraday | faraday (w/ net_http) |
Last updated