Created
October 17, 2009 07:21
-
-
Save hirakuro/212278 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env ruby | |
require "rack" | |
class GoogleCrawlerCollector | |
def save_log | |
open("log.log", "a") do |f| | |
f.puts "-"*40, Time.now | |
f.puts @req.env.map{|k, v| "#{k}: #{v}"}.sort.join("\n"), "" | |
end | |
end | |
def build_response | |
@res.write <<EOT | |
<html> | |
<head><title>Google crawler collect</title></head> | |
<body> | |
<p>Thank you :-)</p> | |
</body> | |
</html> | |
EOT | |
end | |
def call(env) | |
@req = Rack::Request.new(env) | |
@res = Rack::Response.new | |
save_log | |
build_response | |
@res.finish | |
end | |
end | |
Rack::Handler::CGI.run Rack::Builder.app{ | |
use Rack::ShowExceptions | |
use Rack::Lint | |
run GoogleCrawlerCollector.new | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment