青山です。
http-access, KNClient を見ていないので何が問題になっているのかわかりま
せんが、こんな感じではどうでしょうか。Linkavailable: Ruby のトップ 10
には HTTP 1.0 オンリーな所が無かったので HTTP 1.0 では試していませんが、
まあ、おそらくは単に切断されるだけだと思うので、このままいけるような気
がします。(用途を限定しているので、インターフェイスがいまいち)
#!/usr/local/bin/ruby
require "socket"
CR = "\015"
LF = "\012"
EOL = CR + LF
def get_head(host, port, files)
heads = {}
sock = nil
for i in 0 ... files.size
if sock == nil or sock.closed?
sock = TCPsocket.open(host, port)
sock.binmode
STDERR.print "server open.\n"
end
if i == files.size - 1
connection = "Close"
else
connection = "Keep-Alive"
end
sock << "HEAD " << files[i] << " HTTP/1.1" << EOL
sock << "Host: " << host << EOL
sock << "Connection: " << connection << EOL
sock << EOL
head = sock.gets(EOL + EOL)
if /Connection:\s+Close/ni === head
sock.close if not sock.closed?
end
heads[files[i]] = head
end
sock.close if not sock.closed?
heads
end
port = "80"
host = "www.jin.gr.jp"
files = %w[ /~nahi/ /~nahi/Ruby/ /~nahi/link-Ruby.html ]
# Keep-Alive を受け付けないホストの例
#host = "www.isc.meiji.ac.jp"
#files = %w[ /~ee77038/ /~ee77038/ruby/index.html /~ee77038/ruby/program.htm ]
get_head(host, port, files).each do |file, head|
print file, "\n"
print head
end
--
青山 和光 Wakou Aoyama <wakou / fsinet.or.jp>