Skip to content

Instantly share code, notes, and snippets.

@luke-gru
Created June 28, 2011 20:51
Show Gist options
  • Save luke-gru/1052173 to your computer and use it in GitHub Desktop.
Save luke-gru/1052173 to your computer and use it in GitHub Desktop.
#!/usr/bin/env ruby
require 'webrick'
include WEBrick
s = HTTPServer.new(:Port => 2002)
class MyServlet < HTTPServlet::AbstractServlet
def do_GET(req, res)
filecontents = File.open(ENV['HOME'] + "/.hubeyerc", "r") {|f| f.read}
res['Content-type'] = "text/html"
res.body = %{
<html><body>
<p>Hello. You're calling from a #{req['User-Agent']}</p>
<p>I see parameters: #{req.query.keys.join(', ')}</p>
<pre>#{filecontents}</pre>
</body></html>
}
end
end
s.mount("/cool", MyServlet)
trap("INT") { s.shutdown }
s.start
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment