Created
April 23, 2011 02:28
-
-
Save mislav/938183 to your computer and use it in GitHub Desktop.
Faraday SSL example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
connection = Faraday::Connection.new('http://example.com') do |builder| | |
builder.request :url_encoded # for POST/PUT params | |
builder.adapter :net_http | |
end | |
# same as above, short form: | |
connection = Faraday.new 'http://example.com' | |
# GET | |
connection.get '/posts' | |
# POST payload | |
payload = {:title => 'Example'} | |
connection.post '/posts', payload | |
# now again, over SSL | |
# verify_mode is automatically set to OpenSSL::SSL::VERIFY_PEER | |
connection = Faraday.new 'https://example.com' | |
# turn off SSL | |
# (no use-case for this, really) | |
connection = Faraday.new 'https://example.com', :ssl => false | |
# turn off peer verification | |
connection = Faraday.new 'https://example.com', :ssl => {:verify => false} | |
# other SSL options | |
connection = Faraday.new 'https://example.com', :ssl => { | |
:client_cert => ..., | |
:client_key => ..., | |
:ca_file => ..., | |
:ca_path => ..., | |
:cert_store => ... | |
} |
The documentation on this is all wrong. Here's how to do it. This might also work at the request level.
conn = Faraday.new do |faraday|
faraday.ssl.verify = false
end
I had to use the following format for a gem that is both Faraday 0.8 and 0.9 tested.
Faraday.new do |faraday|
faraday.ssl[:verify] = false
end
Many posts seem to think that turning off verification is a good thing, and you are struggling to do it correctly.
Might as well just now use SSL at all if you do that.
The right answer is probably that you need to set up the ca_path so that the server can be validated correctly. See for instance, https://github.com/lostisland/faraday/wiki/Setting-up-SSL-certificates
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I wanted to set TLS 1.2 as the networking protocol with Faraday. So i did Faraday.new(url: uid, ssl: {version: :TLSv1_2}). It works but I am not sure if this is the right configuration. Because i cant break it with Faraday.new(url: uid, ssl: {version: :TLSv10_11}).
Can someone help with the right options for ssl version.