Forum: Ruby proxying HTTPS traffic

Announcement (2017-05-07): www.ruby-forum.com is now read-only since I unfortunately do not have the time to support and maintain the forum any more. Please see rubyonrails.org/community and ruby-lang.org/en/community for other Rails- und Ruby-related community platforms.
05bd4fd102050121a79a5ec0b561ec3a?d=identicon&s=25 robin wood (digininja)
on 2012-08-09 13:34
I'm trying to use Net::HTTP::Proxy to proxy HTTPS traffic and I've got
the following code:

proxy = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port)

http = proxy.start(uri.host)
  if uri.scheme == 'https'
    http.use_ssl = true
    http.verify_mode = OpenSSL::SSL::VERIFY_NONE
  end
  resp = http.get(path)
end

But this complains about the session already being started:

use_ssl value changed, but session already started

How do I get access to the http object to set these values without
starting the proxy?
05bd4fd102050121a79a5ec0b561ec3a?d=identicon&s=25 robin wood (digininja)
on 2012-08-09 17:23
To answer my own question, you have to pass the use_ssl as an optional
parameter when starting the proxy. This works:

require 'net/http'

proxy_uri = URI('http://localhost:8080')
uri = URI('https://www.example.org/')

http = Net::HTTP.new(uri.path)

if uri.scheme == 'https'
  http.use_ssl = true
  http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end

proxy = Net::HTTP::Proxy(proxy_uri.host, proxy_uri.port)
http = proxy.start(uri.host, :use_ssl => true, :verify_mode =>
OpenSSL::SSL::VERIFY_NONE)

resp = http.get(uri.path)

puts resp.code
puts resp.body
This topic is locked and can not be replied to.