Permalink
Browse files

Fix openssl context and host header

Signed-off-by: Sam Phippen <samphippen@googlemail.com>
  • Loading branch information...
samphippen committed Sep 6, 2012
1 parent 3bd40c3 commit f0ac10168417117d6bf9455e01d9c42b8844d5ff
Showing with 8 additions and 3 deletions.
  1. +8 −3 lib/http/client.rb
View
@@ -25,17 +25,17 @@ def body(opts,headers)
# Make an HTTP request
def request(method, uri, options = {})
opts = @default_options.merge(options)
opts.headers["Host"] = URI.parse(uri).host
headers = opts.headers
proxy = opts.proxy
method_body = body(opts, headers)
puts method_body
request = Request.new method, uri, headers, proxy, method_body
if opts.follow
code = 302
while code == 302 or code == 301
puts uri
opts.headers["Host"] = URI.parse(uri).host
method_body = body(opts, headers)
request = Request.new method, uri, headers, proxy, method_body
response = perform request, opts
@@ -57,7 +57,12 @@ def perform(request, options)
socket = options[:socket_class].open(uri.host, uri.port) # TODO: proxy support
if uri.is_a?(URI::HTTPS)
socket = options[:ssl_socket_class].open(socket, options[:ssl_context])
if options[:ssl_context] == nil
context = OpenSSL::SSL::SSLContext.new
else
context = options[:ssl_context]
end
socket = options[:ssl_socket_class].new(socket, context)
socket.connect
end

0 comments on commit f0ac101

Please sign in to comment.