From 8da8547c9869ab429f986517c41984dda0c050f5 Mon Sep 17 00:00:00 2001 From: mariowise Date: Tue, 6 Dec 2016 09:57:14 -0300 Subject: [PATCH] feat(http): read_timout option before request --- lib/pincers/http/client.rb | 1 + lib/pincers/http/session.rb | 5 ++++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/pincers/http/client.rb b/lib/pincers/http/client.rb index e858ce7..a1ba284 100644 --- a/lib/pincers/http/client.rb +++ b/lib/pincers/http/client.rb @@ -16,6 +16,7 @@ def self.build_from_options(_options = {}) session.proxy_auth = _options[:proxy_auth] if _options.key? :proxy_auth session.headers.merge! _options[:headers] if _options.key? :headers session.redirect_limit = _options[:redirect_limit] if _options.key? :redirect_limit + session.read_timeout = _options[:read_timeout] if _options.key? :read_timeout if _options.key? :ssl_cert session.ssl_cert = _options[:ssl_cert] diff --git a/lib/pincers/http/session.rb b/lib/pincers/http/session.rb index e0bb362..5757c93 100644 --- a/lib/pincers/http/session.rb +++ b/lib/pincers/http/session.rb @@ -12,7 +12,7 @@ class Session attr_reader :cookie_jar, :headers attr_accessor :proxy_addr, :proxy_port, :proxy_user, :proxy_password, :redirect_limit, - :ssl_cert, :ssl_key + :ssl_cert, :ssl_key, :read_timeout def initialize(_other = nil) if _other @@ -23,6 +23,7 @@ def initialize(_other = nil) @redirect_limit = _other.redirect_limit @ssl_cert = _other.ssl_cert @ssl_key = _other.ssl_key + @read_timeout = _other.read_timeout || 60 else @headers = DEFAULT_HEADERS @cookie_jar = CookieJar.new @@ -104,6 +105,8 @@ def connect(_uri) proxy_password ) + conn.read_timeout = read_timeout + conn.use_ssl = true if _uri.scheme == 'https' if ssl_cert