Skip to content

Commit

Permalink
follow redirects to https locations & initiate SSL handshake
Browse files Browse the repository at this point in the history
  • Loading branch information
igrigorik committed Mar 12, 2011
1 parent eed8a5f commit 16b4e07
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 4 deletions.
2 changes: 2 additions & 0 deletions lib/em-http/client.rb
Expand Up @@ -104,6 +104,8 @@ def normalize_body(body)
def proxy?; !@options[:proxy].nil?; end
def http_proxy?; proxy? && [nil, :http].include?(@options[:proxy][:type]); end

def ssl?; @req.uri.scheme == "https" || @req.uri.port == 443; end

def continue?
@response_header.status == 100 && (@method == 'POST' || @method == 'PUT')
end
Expand Down
12 changes: 9 additions & 3 deletions lib/em-http/http_connection.rb
Expand Up @@ -87,15 +87,16 @@ def receive_data(data)

def connection_completed
if @opts.proxy && @opts.proxy[:type] == :socks5
socksify(@opts.uri.host, @opts.uri.port, *@opts.proxy[:authorization]) { start }
socksify(client.req.uri.host, client.req.uri.port, *@opts.proxy[:authorization]) { start }

else
start
end
end

def start
ssl = @opts.options[:tls] || @opts.options[:ssl] || {}
start_tls(ssl) if @opts.uri.scheme == "https" or @opts.uri.port == 443
start_tls(ssl) if client && client.ssl?

succeed
end
Expand Down Expand Up @@ -124,7 +125,12 @@ def unbind
@clients.pop.close(e.message)
end
end

end

private

def client
@clients.first
end
end
end
2 changes: 1 addition & 1 deletion lib/em-http/version.rb
@@ -1,5 +1,5 @@
module EventMachine
class HttpRequest
VERSION = "1.0.0.beta.2"
VERSION = "1.0.0.beta.3"
end
end
12 changes: 12 additions & 0 deletions spec/external_spec.rb
Expand Up @@ -15,6 +15,18 @@
}
end

it "should follow redirect to https and initiate the handshake" do
EventMachine.run {
http = EventMachine::HttpRequest.new('http://analytics.postrank.com/').get :redirects => 5

http.errback { failed(http) }
http.callback {
http.response_header.status.should == 200
EventMachine.stop
}
}
end

it "should perform a streaming GET" do
EventMachine.run {

Expand Down

0 comments on commit 16b4e07

Please sign in to comment.