Reputation: 2328
I'm trying
RestClient.add_before_execution_proc do |req, params|
req(:verify_ssl => false)
end
It isn't working.
How can I wrap every request with RestClient to use :verify_ssl => false?
Upvotes: 1
Views: 3323
Reputation: 106598
In response to @alb-i986's comment for @AlexandreAngelim's answer, I've written the follow monkey patch that wraps the constructor of RestClient::Request
class instead so it would work with the latest RestClient
:
module RestClient
class Request
orig_initialize = instance_method(:initialize)
define_method(:initialize) do |args|
args[:verify_ssl] = false
orig_initialize.bind(self).(args)
end
end
end
Upvotes: 0
Reputation: 8866
I'd write my own helper wrapper for the RestClient calls rather than modifying global state, since global changes make it hard for someone reading your code to understand what's happening.
For example:
def insecure_restclient_get(url, headers={}, &block)
RestClient::Request.execute(verify_ssl: false, method: :get, url: url, headers: headers, &block)
end
def insecure_restclient_post(url, payload, headers={}, &block)
RestClient::Request.execute(verify_ssl: false, method: :post, url: url, payload: payload, headers: headers, &block)
end
Also note that if you're setting verify_ssl: false
you might as well not be using https at all.
Upvotes: 1
Reputation: 5795
You can also consider creating a simple class to encapsulate your needs and execute a get/post/... rest without verify_ssl
(check https://github.com/rest-client/rest-client/blob/master/lib/restclient/request.rb#L160)
Upvotes: 1
Reputation: 6753
Use the params
instead of req
. Those params will be passed to RestClient.execute
, which is the entry point for all requests.
RestClient.add_before_execution_proc do |req, params|
params[:verify_ssl] = false
end
Upvotes: 3