Permalink
Browse files

Support SSL in Request

Ported SSL options from Easy to Request.
There should be only one interface in the API (Request).
  • Loading branch information...
1 parent 9010041 commit 46a1b9b2ed0db415e17308ecc612264d92d55447 @gravis gravis committed Jun 15, 2010
Showing with 52 additions and 1 deletion.
  1. +11 −0 README.textile
  2. +7 −0 lib/typhoeus/hydra.rb
  3. +34 −1 lib/typhoeus/request.rb
View
@@ -216,6 +216,17 @@ e.ssl_key = "akey.key"
e.perform
</pre>
+or directly to a Typhoeus::Request :
+
+<pre>
+e = Typhoeus::Request.get("https://example.com/action",
+ :ssl_cacert => "ca_file.cer",
+ :ssl_cert => "acert.crt",
+ :ssl_key => "akey.key",
+ [...]
+end
+</pre>
+
h2. NTLM authentication
Thanks for the authentication piece and this description go to Oleg Ivanov (morhekil). The major reason to start this fork was the need to perform NTLM authentication in Ruby. Now you can do it via Typhoeus::Easy interface using the following API.
@@ -142,6 +142,13 @@ def get_easy_object(request)
easy.max_redirects = request.max_redirects if request.max_redirects
easy.proxy = request.proxy if request.proxy
easy.disable_ssl_peer_verification if request.disable_ssl_peer_verification
+ easy.ssl_cert = request.ssl_cert
+ easy.ssl_cert_type = request.ssl_cert_type
+ easy.ssl_key = request.ssl_key
+ easy.ssl_key_type = request.ssl_key_type
+ easy.ssl_key_password = request.ssl_key_password
+ easy.ssl_cacert = request.ssl_cacert
+ easy.ssl_capath = request.ssl_capath
easy.on_success do |easy|
queue_next
@@ -1,8 +1,34 @@
module Typhoeus
class Request
- attr_accessor :method, :params, :body, :headers, :timeout, :user_agent, :response, :cache_timeout, :follow_location, :max_redirects, :proxy, :disable_ssl_peer_verification
+ attr_accessor :method, :params, :body, :headers, :timeout, :user_agent, :response, :cache_timeout, :follow_location, :max_redirects, :proxy, :disable_ssl_peer_verification, :ssl_cert, :ssl_cert_type, :ssl_key, :ssl_key_type, :ssl_key_password, :ssl_cacert, :ssl_capath
+
+
attr_reader :url
+ # Initialize a new Request
+ #
+ # Options:
+ # * +url+ : Endpoint (URL) of the request
+ # * +options+ : A hash containing options among :
+ # ** +:method+ : :get (default) / :post / :put
+ # ** +:params+ : params as a Hash
+ # ** +:body+
+ # ** +:timeout+ : timeout (ms)
+ # ** +:headers+ : headers as Hash
+ # ** +:user_agent+ : user agent (string)
+ # ** +:cache_timeout+ : cache timeout (ms)
+ # ** +:follow_location
+ # ** +:max_redirects
+ # ** +:proxy
+ # ** +:disable_ssl_peer_verification
+ # ** +:ssl_cert
+ # ** +:ssl_cert_type
+ # ** +:ssl_key
+ # ** +:ssl_key_type
+ # ** +:ssl_key_password
+ # ** +:ssl_cacert
+ # ** +:ssl_capath
+ #
def initialize(url, options = {})
@method = options[:method] || :get
@params = options[:params]
@@ -15,6 +41,13 @@ def initialize(url, options = {})
@max_redirects = options[:max_redirects]
@proxy = options[:proxy]
@disable_ssl_peer_verification = options[:disable_ssl_peer_verification]
+ @ssl_cert = options[:ssl_cert]
+ @ssl_cert_type = options[:ssl_cert_type]
+ @ssl_key = options[:ssl_key]
+ @ssl_key_type = options[:ssl_key_type]
+ @ssl_key_password = options[:ssl_key_password]
+ @ssl_cacert = options[:ssl_cacert]
+ @ssl_capath = options[:ssl_capath]
if @method == :post
@url = url

0 comments on commit 46a1b9b

Please sign in to comment.