require 'webrick'
require 'webrick/httpproxy'
require 'uri'
require 'kconv'
$KCODE = 'utf8'
handler = Proc.new{ |req, res|
=begin
if res.body.to_s.size > 1 and res['content-type'].match(/text\/html/) then
ms = '。'; cs = 'うぇ〜い。'
if str = res.body.to_s.toutf8.gsub!(/#{ms}/m, cs) then
res.body = str.tosjis if res.body.to_s.issjis
res.body = str.toeuc if res.body.to_s.iseuc
end
end
=end
uri = req.request_uri
path = uri.path.dup
path << "?" << uri.query if uri.query
$data.print [uri.host, path, res.status, res['content-type']].join(','), "\n"
}
s = WEBrick::HTTPProxyServer.new(
:BindAddress => '127.0.0.1',
:Port => 8080,
:Logger => WEBrick::Log::new("log.txt", WEBrick::Log::DEBUG),
:ProxyVia => false,
:ProxyURI => URI.parse(''),
:ProxyContentHandler => handler
)
Signal.trap('INT') do
s.shutdown
$data.close
end
$data = File.open("data.txt", "a")
s.start