Skip to content

Instantly share code, notes, and snippets.

@dtchepak
Last active September 12, 2022 07:24
Show Gist options
  • Star 12 You must be signed in to star a gist
  • Fork 5 You must be signed in to fork a gist
  • Save dtchepak/13b53eef9dc6b65ae1ad to your computer and use it in GitHub Desktop.
Save dtchepak/13b53eef9dc6b65ae1ad 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
@mqu
Copy link

mqu commented Aug 10, 2022

thanks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment