Skip to content

Instantly share code, notes, and snippets.

@phillmv
Created February 13, 2012 05:12
Show Gist options
  • Save phillmv/1813858 to your computer and use it in GitHub Desktop.
Save phillmv/1813858 to your computer and use it in GitHub Desktop.
test_request.rb
require 'webrick'
begin
require 'pry'
rescue LoadError
begin
require 'ruby-debug'
rescue LoadError
end
end
include WEBrick
# Adapted from http://microjet.ath.cx/webrickguide/html/Contents.html
def start_webrick(config = {})
# always listen on port 8080
config.update(:Port => 8080)
server = HTTPServer.new(config)
yield server if block_given?
['INT', 'TERM'].each {|signal|
trap(signal) {server.shutdown}
}
server.start
end
start_webrick {|server|
my_wonderful_proc = Proc.new {|req, resp|
puts "##############"
puts req.to_s
resp.body = ""
}
server.mount('/', HTTPServlet::ProcHandler.new(my_wonderful_proc))
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment