1#!/usr/bin/env ruby
2
3require 'net/https'
4require 'optparse'
5
6options = ARGV.getopts('C:')
7
8cert_store = options["C"]
9
10uri = URI.parse(ARGV[0])
11if proxy = ENV['HTTP_PROXY']
12  prx_uri = URI.parse(proxy)
13  prx_host = prx_uri.host
14  prx_port = prx_uri.port
15end
16
17h = Net::HTTP.new(uri.host, uri.port, prx_host, prx_port)
18h.set_debug_output($stderr) if $DEBUG
19if uri.scheme == "https"
20  h.use_ssl = true
21  if cert_store
22    if File.directory?(cert_store)
23      h.ca_path = cert_store
24    else
25      h.ca_file = cert_store
26    end
27  end
28end
29
30path = uri.path.empty? ? "/" : uri.path
31h.get2(path){|resp|
32  STDERR.puts h.peer_cert.inspect if h.peer_cert
33  print resp.body
34}
35