Skip to content

Instantly share code, notes, and snippets.

@supairish
Forked from dtchepak/echo.rb
Created February 6, 2019 22:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save supairish/f0c4e0f91a4fe30d1d24a1c4dc740816 to your computer and use it in GitHub Desktop.
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/.
# 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