Skip to content

Instantly share code, notes, and snippets.

@marcosccm
Last active December 21, 2015 03:58
Show Gist options
  • Save marcosccm/6245538 to your computer and use it in GitHub Desktop.
Save marcosccm/6245538 to your computer and use it in GitHub Desktop.
WEBrick dummy server
require 'webrick'
json = File.read("./file.json")
class Server < WEBrick::HTTPServlet::AbstractServlet
def initialize(server, json)
super(server)
@json = json
end
def do_GET(request, response)
response.status = 200
response['Content-Type'] = 'application/text'
response.body = @json
end
end
server = WEBrick::HTTPServer.new :Port => 8000
server.mount "/bla", Server, json
trap 'INT' do server.shutdown end
pid = fork { server.start }
puts `curl localhost:8000/bla --max-time 1` # then I can talk to the webrick
Process.kill('INT', pid)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment