-
-
Save supairish/f0c4e0f91a4fe30d1d24a1c4dc740816 to your computer and use it in GitHub Desktop.
Simple Ruby HTTP server to echo whatever GET or POST requests come through. Largely based on https://www.igvita.com/2007/02/13/building-dynamic-webrick-servers-in-ruby/.
This file contains hidden or 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
# Reference: https://www.igvita.com/2007/02/13/building-dynamic-webrick-servers-in-ruby/ | |
require 'webrick' | |
class Echo < WEBrick::HTTPServlet::AbstractServlet | |
def do_GET(request, response) | |
puts request | |
response.status = 200 | |
end | |
def do_POST(request, response) | |
puts request | |
response.status = 200 | |
end | |
end | |
server = WEBrick::HTTPServer.new(:Port => 8080) | |
server.mount "/", Echo | |
trap "INT" do server.shutdown end | |
server.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment