lib/almodovar/http_client.rb in almodovar-1.4.0 vs lib/almodovar/http_client.rb in almodovar-1.5.0
- old
+ new
@@ -1,25 +1,21 @@
require 'httpclient'
module Almodovar
class HttpClient
-
attr_accessor :client,
:headers,
:username,
:password,
:auth_type
delegate :agent_name=,
:connect_timeout=,
+ :send_timeout=,
+ :receive_timeout=,
:to => :client
-
- def timeout=(value)
- client.send_timeout = value
- end
-
def initialize
@client = HTTPClient.new
end
def get(uri, headers = {})
@@ -69,18 +65,24 @@
client.set_auth(domain, username, password)
end
end
def request(method, uri, options = {})
- uri = URI.parse(uri)
+ uri = URI.parse(URI.escape(URI.unescape(uri)))
if (requires_auth?)
domain = domain_for(uri)
uri.user = username
uri.password = password
set_client_auth(domain)
end
client.request(method, uri, :body => options[:body], :header => options[:headers].stringify_keys || {}, :follow_redirect => true)
+ rescue HTTPClient::SendTimeoutError => e
+ raise SendTimeoutError.new(e)
+ rescue HTTPClient::ReceiveTimeoutError => e
+ raise ReceiveTimeoutError.new(e)
+ rescue HTTPClient::ConnectTimeoutError => e
+ raise ConnectTimeoutError.new(e)
end
end
class AuthContext
attr_accessor :username, :password, :domain
@@ -98,7 +100,6 @@
end
class HttpResponse
attr_accessor :status, :body
end
-
-end
\ No newline at end of file
+end