aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGOTOU Yuuzou <gotoyuzo@notwork.org>2003-07-01 18:08:39 +0000
committerGOTOU Yuuzou <gotoyuzo@notwork.org>2003-07-01 18:08:39 +0000
commit93598e364c7f6fa3327816aa6689e00733a089fa (patch)
tree15591655a92cd66d3e9ec9a50609f2769b5bad26
parentfc27ef9f88da0777358fd1cd4523ae848dde3b5c (diff)
downloadruby-openssl-history-93598e364c7f6fa3327816aa6689e00733a089fa.tar.gz
revised
-rw-r--r--examples/ssl/wget2.rb35
1 files changed, 9 insertions, 26 deletions
diff --git a/examples/ssl/wget2.rb b/examples/ssl/wget2.rb
index 4d6a36b..a8a8915 100644
--- a/examples/ssl/wget2.rb
+++ b/examples/ssl/wget2.rb
@@ -4,40 +4,23 @@ require 'net/https'
require 'getopts'
begin require 'verify_cb'; rescue LoadError; end
-getopts 'v', 'p:'
+getopts 'v'
-uri = ARGV[0]
-if %r!(https?)://(.*?)(?::(\d+))?(/.*)! =~ uri
- scheme = $1
- host = $2
- port = $3 ? $3.to_i : Socket.getservbyname(scheme)
- path = $4 || "/"
-else
- STDERR.print "Invalid URI.\n"
- exit 2
-end
-
-# parse HTTP_PROXY environment variable.
+uri = URI.parse(ARGV[0])
if proxy = ENV['HTTP_PROXY']
- if %r!(http)://(.*?)(?::(\d+))?(/.*)! =~ proxy
- p_scheme = $1
- p_host = $2
- p_port = $3 ? $3.to_i : Socket.getservbyname(p_scheme)
- else
- STDERR.print "Invalid HTTP_PROXY.\n"
- exit 2
- end
+ prx_uri = URI.parse(proxy)
+ prx_host = prx_uri.host
+ prx_port = prx_uri.port
end
-h = Net::HTTP.new(host, port, p_host, p_port)
-h.set_pipe($stderr) if $DEBUG
-if scheme == "https"
+h = Net::HTTP.new(uri.host, uri.port, prx_host, prx_port)
+h.set_debug_output($stderr) if $DEBUG
+if uri.scheme == "https"
h.use_ssl = true
h.verify_mode = SSL::VERIFY_PEER if $OPT_v
h.verify_callback = VerifyCallbackProc if defined? VerifyCallbackProc
end
-h.get2(path){ |resp|
+h.get2(uri.path){|resp|
STDERR.puts h.peer_cert.inspect if h.peer_cert
print resp.body
}
-