Skip to content

Instantly share code, notes, and snippets.

@cori
Forked from dtchepak/echo.rb
Created September 25, 2018 02:38
Show Gist options
  • Save cori/e01812117e0f44a8dfbb05fb9f37df04 to your computer and use it in GitHub Desktop.
Save cori/e01812117e0f44a8dfbb05fb9f37df04 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
@cori
Copy link
Author

cori commented Sep 25, 2018

puts writes its param to the webrick console

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