summaryrefslogtreecommitdiff
path: root/sample/dualstack-fetch.rb
diff options
context:
space:
mode:
authormatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-05-25 15:01:48 +0000
committermatz <matz@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2001-05-25 15:01:48 +0000
commit67355a8c56b8d3a44aa336a31ec3db116cba45e9 (patch)
treec9ee3a2a40a06581c37296a3c8435c1494cf5993 /sample/dualstack-fetch.rb
parent8a8d0b2cd1bfda4f6266e108da5f11cd3c54d1da (diff)
* string.c (rb_str_replace): add taint status infection
(OBJ_INFECT()). * string.c (rb_str_crypt): ditto. * string.c (rb_str_ljust): ditto. * string.c (rb_str_rjust): ditto. * string.c (rb_str_center): ditto. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_6@1455 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'sample/dualstack-fetch.rb')
-rw-r--r--sample/dualstack-fetch.rb48
1 files changed, 48 insertions, 0 deletions
diff --git a/sample/dualstack-fetch.rb b/sample/dualstack-fetch.rb
new file mode 100644
index 0000000000..ab8d0914f2
--- /dev/null
+++ b/sample/dualstack-fetch.rb
@@ -0,0 +1,48 @@
+# simple webpage fetcher
+
+# The code demonstrates how a multi-protocol client should be written.
+# TCPsocket is using getaddrinfo() internally, so there should be no problem.
+
+require "socket"
+
+if ARGV.size != 1
+ STDERR.print "requires URL\n"
+ exit
+end
+
+url = ARGV[0]
+if url !~ /^http:\/\/([^\/]+)(\/.*)$/
+ STDERR.print "only http with full hostname is supported\n"
+ exit
+end
+
+# split URL into host, port and path
+hostport = $1
+path = $2
+if (hostport =~ /^(.*):([0-9]+)$/)
+ host = $1
+ port = $2
+else
+ host = hostport
+ port = 80
+end
+if host =~ /^\[(.*)\]$/
+ host = $1
+end
+
+#STDERR.print "url=<#{ARGV[0]}>\n"
+#STDERR.print "host=<#{host}>\n"
+#STDERR.print "port=<#{port}>\n"
+#STDERR.print "path=<#{path}>\n"
+
+STDERR.print "conntecting to #{host} port #{port}\n"
+c = TCPsocket.new(host, port)
+dest = Socket.getnameinfo(c.getpeername,
+ Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV)
+STDERR.print "conntected to #{dest[0]} port #{dest[1]}\n"
+c.print "GET #{path} HTTP/1.0\n"
+c.print "Host: #{host}\n"
+c.print "\n"
+while c.gets
+ print
+end