Created
January 10, 2019 09:11
-
-
Save mensfeld/7af5b24a404432738e3adf821b94f344 to your computer and use it in GitHub Desktop.
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
require 'webrick' | |
require 'set' | |
server = WEBrick::HTTPServer.new(Port: 3000) | |
set = Set.new | |
server.mount_proc '/' do |req, res| | |
data, action = req.body.split(',') | |
action ||= 'ADD' | |
# Return set data for any command, no need to handle GET | |
case action | |
when 'ADD' | |
set.add(data) | |
when 'DEL' | |
set.delete(data) | |
end | |
res.body = set.to_a.to_s | |
end | |
trap('INT') { server.shutdown } | |
server.start |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment