Permalink
Browse files

expose CONNECTTIMEOUT curl option to the Easy and Request objects.

  • Loading branch information...
1 parent fdf967e commit 1b6f5ac07ce082e47f561438e32c0e2d49b1e3de @balexis balexis committed with Alexis Dorais-Joncas Jul 14, 2010
Showing with 15 additions and 3 deletions.
  1. +1 −1 examples/twitter.rb
  2. +10 −0 lib/typhoeus/easy.rb
  3. +1 −0 lib/typhoeus/hydra.rb
  4. +3 −2 lib/typhoeus/request.rb
View
2 examples/twitter.rb
@@ -1,5 +1,5 @@
-require File.dirname(__FILE__) + '/../lib/typhoeus.rb'
require 'rubygems'
+require File.dirname(__FILE__) + '/../lib/typhoeus.rb'
require 'json'
class Twitter
View
10 lib/typhoeus/easy.rb
@@ -16,6 +16,10 @@ class Easy
:CURLOPT_POSTFIELDSIZE => 60,
:CURLOPT_USERAGENT => 10018,
:CURLOPT_TIMEOUT_MS => 155,
+ # Time-out connect operations after this amount of milliseconds.
+ # [Only works on unix-style/SIGALRM operating systems. IOW, does
+ # not work on Windows.
+ :CURLOPT_CONNECTTIMEOUT_MS => 156,
:CURLOPT_NOSIGNAL => 99,
:CURLOPT_HTTPHEADER => 10023,
:CURLOPT_FOLLOWLOCATION => 52,
@@ -100,6 +104,12 @@ def follow_location=(boolean)
def max_redirects=(redirects)
set_option(OPTION_VALUES[:CURLOPT_MAXREDIRS], redirects)
end
+
+ def connect_timeout=(milliseconds)
+ @connect_timeout = milliseconds
+ set_option(OPTION_VALUES[:CURLOPT_NOSIGNAL], 1)
+ set_option(OPTION_VALUES[:CURLOPT_CONNECTTIMEOUT_MS], milliseconds)
+ end
def timeout=(milliseconds)
@timeout = milliseconds
View
1 lib/typhoeus/hydra.rb
@@ -138,6 +138,7 @@ def get_easy_object(request)
easy.headers = request.headers if request.headers
easy.request_body = request.body if request.body
easy.timeout = request.timeout if request.timeout
+ easy.connect_timeout = request.connect_timeout if request.connect_timeout
easy.follow_location = request.follow_location if request.follow_location
easy.max_redirects = request.max_redirects if request.max_redirects
easy.proxy = request.proxy if request.proxy
View
5 lib/typhoeus/request.rb
@@ -1,7 +1,6 @@
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, :ssl_cert, :ssl_cert_type, :ssl_key, :ssl_key_type, :ssl_key_password, :ssl_cacert, :ssl_capath, :verbose
-
+ attr_accessor :method, :params, :body, :headers, :connect_timeout, :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, :verbose
attr_reader :url
@@ -14,6 +13,7 @@ class Request
# ** +:params+ : params as a Hash
# ** +:body+
# ** +:timeout+ : timeout (ms)
+ # ** +:connect_timeout+ : connect timeout (ms)
# ** +:headers+ : headers as Hash
# ** +:user_agent+ : user agent (string)
# ** +:cache_timeout+ : cache timeout (ms)
@@ -35,6 +35,7 @@ def initialize(url, options = {})
@params = options[:params]
@body = options[:body]
@timeout = options[:timeout]
+ @connect_timeout = options[:connect_timeout]
@headers = options[:headers] || {}
@user_agent = options[:user_agent] || Typhoeus::USER_AGENT
@cache_timeout = options[:cache_timeout]

0 comments on commit 1b6f5ac

Please sign in to comment.