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
|
else
|
||||||
file_logger = Class.new do
|
file_logger = Class.new do
|
||||||
attr_writer :target_file
|
attr_writer :target_file
|
||||||
|
|
||||||
def << obj
|
def << obj
|
||||||
File.open(@target_file, 'a') { |f| f.puts obj }
|
File.open(@target_file, 'a') { |f| f.puts obj }
|
||||||
end
|
end
|
||||||
|
@ -148,4 +149,15 @@ module RestClient
|
||||||
@@env_log || @@log
|
@@env_log || @@log
|
||||||
end
|
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
|
end
|
||||||
|
|
|
@ -21,11 +21,10 @@ module RestClient
|
||||||
# * :ssl_client_cert, :ssl_client_key, :ssl_ca_file
|
# * :ssl_client_cert, :ssl_client_key, :ssl_ca_file
|
||||||
class Request
|
class Request
|
||||||
|
|
||||||
attr_reader :method, :url, :payload, :headers, :processed_headers,
|
attr_reader :method, :url, :headers, :cookies,
|
||||||
:cookies, :user, :password, :timeout, :open_timeout,
|
:payload, :user, :password, :timeout,
|
||||||
:verify_ssl, :ssl_client_cert, :ssl_client_key, :ssl_ca_file,
|
:open_timeout, :raw_response, :verify_ssl, :ssl_client_cert,
|
||||||
:raw_response
|
:ssl_client_key, :ssl_ca_file, :processed_headers, :args
|
||||||
|
|
||||||
|
|
||||||
def self.execute(args, &block)
|
def self.execute(args, &block)
|
||||||
new(args).execute &block
|
new(args).execute &block
|
||||||
|
@ -48,6 +47,7 @@ module RestClient
|
||||||
@ssl_ca_file = args[:ssl_ca_file] || nil
|
@ssl_ca_file = args[:ssl_ca_file] || nil
|
||||||
@tf = nil # If you are a raw request, this is your tempfile
|
@tf = nil # If you are a raw request, this is your tempfile
|
||||||
@processed_headers = make_headers headers
|
@processed_headers = make_headers headers
|
||||||
|
@args = args
|
||||||
end
|
end
|
||||||
|
|
||||||
def execute &block
|
def execute &block
|
||||||
|
@ -152,6 +152,10 @@ module RestClient
|
||||||
net.read_timeout = @timeout if @timeout
|
net.read_timeout = @timeout if @timeout
|
||||||
net.open_timeout = @open_timeout if @open_timeout
|
net.open_timeout = @open_timeout if @open_timeout
|
||||||
|
|
||||||
|
RestClient.before_execution_procs.each do |b|
|
||||||
|
b.call(req, params)
|
||||||
|
end
|
||||||
|
|
||||||
log_request
|
log_request
|
||||||
|
|
||||||
net.start do |http|
|
net.start do |http|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue