mirror of
https://github.com/rest-client/rest-client.git
synced 2022-11-09 13:49:40 -05:00
Another try
This commit is contained in:
parent
6266f7aec6
commit
1c7eaa3834
2 changed files with 21 additions and 5 deletions
|
@ -126,6 +126,7 @@ module RestClient
|
|||
else
|
||||
file_logger = Class.new do
|
||||
attr_writer :target_file
|
||||
|
||||
def << obj
|
||||
File.open(@target_file, 'a') { |f| f.puts obj }
|
||||
end
|
||||
|
@ -148,4 +149,15 @@ module RestClient
|
|||
@@env_log || @@log
|
||||
end
|
||||
|
||||
@@before_execution_procs = []
|
||||
|
||||
# Add a Proc to be called before each request in executed
|
||||
def self.add_before_execution_proc &proc
|
||||
@@before_execution_procs << proc
|
||||
end
|
||||
|
||||
def self.before_execution_procs # :nodoc:
|
||||
@@before_execution_procs
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
@ -21,11 +21,10 @@ module RestClient
|
|||
# * :ssl_client_cert, :ssl_client_key, :ssl_ca_file
|
||||
class Request
|
||||
|
||||
attr_reader :method, :url, :payload, :headers, :processed_headers,
|
||||
:cookies, :user, :password, :timeout, :open_timeout,
|
||||
:verify_ssl, :ssl_client_cert, :ssl_client_key, :ssl_ca_file,
|
||||
:raw_response
|
||||
|
||||
attr_reader :method, :url, :headers, :cookies,
|
||||
:payload, :user, :password, :timeout,
|
||||
:open_timeout, :raw_response, :verify_ssl, :ssl_client_cert,
|
||||
:ssl_client_key, :ssl_ca_file, :processed_headers, :args
|
||||
|
||||
def self.execute(args, &block)
|
||||
new(args).execute &block
|
||||
|
@ -48,6 +47,7 @@ module RestClient
|
|||
@ssl_ca_file = args[:ssl_ca_file] || nil
|
||||
@tf = nil # If you are a raw request, this is your tempfile
|
||||
@processed_headers = make_headers headers
|
||||
@args = args
|
||||
end
|
||||
|
||||
def execute &block
|
||||
|
@ -152,6 +152,10 @@ module RestClient
|
|||
net.read_timeout = @timeout if @timeout
|
||||
net.open_timeout = @open_timeout if @open_timeout
|
||||
|
||||
RestClient.before_execution_procs.each do |b|
|
||||
b.call(req, params)
|
||||
end
|
||||
|
||||
log_request
|
||||
|
||||
net.start do |http|
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue