lib/em-http/request.rb in em-http-request-0.2.4 vs lib/em-http/request.rb in em-http-request-0.2.5
- old
+ new
@@ -7,11 +7,10 @@
# of the response. Response is parsed with a Ragel-generated whitelist parser
# which supports chunked HTTP encoding.
#
# == Example
#
- #
# EventMachine.run {
# http = EventMachine::HttpRequest.new('http://127.0.0.1/').get :query => {'keyname' => 'value'}
#
# http.callback {
# p http.response_header.status
@@ -56,25 +55,34 @@
protected
def setup_request(method, options)
raise ArgumentError, "invalid request path" unless /^\// === @uri.path
-
@options = options
+
+ if proxy = options[:proxy]
+ @host_to_connect = proxy[:host]
+ @port_to_connect = proxy[:port]
+ else
+ @host_to_connect = @uri.host
+ @port_to_connect = @uri.port
+ end
+
+ # default connect & inactivity timeouts
+ @options[:timeout] = 10 if not @options[:timeout]
- # default connect & inactivity timeouts
- @options[:timeout] = 5 if not @options[:timeout]
-
- # Make sure the port is set as Addressable::URI doesn't set the
- # port if it isn't there.
+ # Make sure the ports are set as Addressable::URI doesn't
+ # set the port if it isn't there
@uri.port ||= 80
+ @port_to_connect ||= 80
+
@method = method.to_s.upcase
send_request
end
def send_request
begin
- EventMachine.connect(@uri.host, @uri.port, EventMachine::HttpClient) { |c|
+ EventMachine.connect(@host_to_connect, @port_to_connect, EventMachine::HttpClient) { |c|
c.uri = @uri
c.method = @method
c.options = @options
c.comm_inactivity_timeout = @options[:timeout]
c.pending_connect_timeout = @options[:timeout]
\ No newline at end of file