Permalink
Browse files

Add CONNECT proxy support [Fixes #146]

  • Loading branch information...
1 parent ff935e8 commit 42de69f559800ea122ff32cf78226d0c578579ac @ConradIrwin ConradIrwin committed Jun 8, 2013
Showing with 28 additions and 0 deletions.
  1. +1 −0 em-http-request.gemspec
  2. +1 −0 lib/em-http.rb
  3. +3 −0 lib/em-http/http_connection.rb
  4. +23 −0 spec/connectify_proxy_spec.rb
View
@@ -18,6 +18,7 @@ Gem::Specification.new do |s|
s.add_dependency "addressable", ">= 2.2.3"
s.add_dependency "http_parser.rb", ">= 0.5.3"
s.add_dependency "em-socksify"
+ s.add_dependency "em-connectify"
s.add_dependency "cookiejar"
s.add_development_dependency "rspec"
View
@@ -1,5 +1,6 @@
require 'eventmachine'
require 'em-socksify'
+require 'em-connectify'
require 'addressable/uri'
require 'http/parser'
@@ -35,6 +35,7 @@ def unbind(reason=nil)
class HttpConnection
include HTTPMethods
include Socksify
+ include Connectify
attr_reader :deferred
attr_accessor :error, :connopts, :uri, :conn
@@ -150,6 +151,8 @@ def connection_completed
if @connopts.proxy && @connopts.proxy[:type] == :socks5
socksify(client.req.uri.host, client.req.uri.port, *@connopts.proxy[:authorization]) { start }
+ elsif @connopts.proxy && @connopts.proxy[:type] == :connect
+ connectify(client.req.uri.host, client.req.uri.port) { start }
else
start
end
@@ -0,0 +1,23 @@
+require 'helper'
+
+requires_connection do
+ requires_port(3128) do
+ describe EventMachine::HttpRequest do
+
+ let(:proxy) { {:proxy => { :host => '127.0.0.1', :port => 3128, :type => :connect }} }
+
+ it "should use CONNECT proxy" do
+ EventMachine.run {
+ http = EventMachine::HttpRequest.new('http://jsonip.com/', proxy).get
+
+ http.errback { failed(http) }
+ http.callback {
+ http.response_header.status.should == 200
+ http.response.should match('173.230.151.99')
+ EventMachine.stop
+ }
+ }
+ end
+ end
+ end
+end

0 comments on commit 42de69f

Please sign in to comment.