1
0
Fork 0
mirror of https://github.com/rest-client/rest-client.git synced 2022-11-09 13:49:40 -05:00

Add before_execution_proc support to Requests.

This makes it possible for individual requests to carry independent
before_execution_procs. (We're slowly getting rid of the messy global
configuration.)

Fixes: #137
This commit is contained in:
Andy Brody 2015-06-09 23:55:49 -07:00
parent 726772e41c
commit 58c61be229
2 changed files with 12 additions and 0 deletions

View file

@ -51,6 +51,9 @@ This release is largely API compatible, but makes several breaking changes.
- When following HTTP redirection, store a list of each previous response on
the response object as `.history`. This makes it possible to access the
original response headers and body before the redirection was followed.
- Add `:before_execution_proc` option to `RestClient::Request`. This makes it
possible to add procs like `RestClient.add_before_execution_proc` to a single
request without global state.
# 1.8.0

View file

@ -33,6 +33,9 @@ module RestClient
# * :ssl_version specifies the SSL version for the underlying Net::HTTP connection
# * :ssl_ciphers sets SSL ciphers for the connection. See
# OpenSSL::SSL::SSLContext#ciphers=
# * :before_execution_proc a Proc to call before executing the request. This
# proc, like procs from RestClient.before_execution_procs, will be
# called with the HTTP request and request params.
class Request
# TODO: rename timeout to read_timeout
@ -186,6 +189,8 @@ module RestClient
@max_redirects = args[:max_redirects] || 10
@processed_headers = make_headers headers
@args = args
@before_execution_proc = args[:before_execution_proc]
end
def execute & block
@ -479,6 +484,10 @@ module RestClient
before_proc.call(req, args)
end
if @before_execution_proc
@before_execution_proc.call(req, args)
end
log_request