From c0010e4940dd0ca067d469d8194be69b2bc1dece Mon Sep 17 00:00:00 2001 From: Adam Frisby Date: Tue, 6 Nov 2007 21:41:11 +0000 Subject: * Moved /branches/ruby to /trunk/share/ruby --- share/ruby/aserv.rb | 35 +++++++++++++++++++++++++++++++++++ 1 file changed, 35 insertions(+) create mode 100644 share/ruby/aserv.rb (limited to 'share/ruby/aserv.rb') diff --git a/share/ruby/aserv.rb b/share/ruby/aserv.rb new file mode 100644 index 0000000..1ac3d60 --- /dev/null +++ b/share/ruby/aserv.rb @@ -0,0 +1,35 @@ +require "webrick" + +# +# Dummy asset server +# + +class AssetServlet < WEBrick::HTTPServlet::AbstractServlet + def do_GET(req, res) + uuid = req.path.split("/")[2].downcase.gsub(/[^0-9a-f]+/, "") + if uuid.length == 32 + # length is correct + File.open("assets/#{uuid}/data") do |f| + res.body = f.read + end + end + # res["content-type"] = "text/plain" # or what do we set it to ? + end + def do_POST(req, res) + uuid = req.path.split("/")[2].downcase.gsub(/[^0-9a-f]+/, "") + if uuid.length == 32 + Dir.mkdir("assets/#{uuid}") + File.open("assets/#{uuid}/data", "wb") do |f| + f.write req.body + STDERR.print "Written #{req.body.length} bytes for uuid #{uuid}\n\n" + end + end + end +end + + +svr = WEBrick::HTTPServer.new(:Port=>8003) +svr.mount("/assets", AssetServlet, 5000000) +trap(:INT){ svr.shutdown } +svr.start + -- cgit v1.1