Forum: Ruby proxying HTTPS traffic

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
Please log in before posting. Registration is free and takes only a minute.
Existing account

NEW: Do you have a Google/GoogleMail, Yahoo or Facebook account? No registration required!
Log in with Google account | Log in with Yahoo account | Log in with Facebook account
No account? Register here.