diff options
author | Adam Frisby | 2007-11-06 21:41:11 +0000 |
---|---|---|
committer | Adam Frisby | 2007-11-06 21:41:11 +0000 |
commit | c0010e4940dd0ca067d469d8194be69b2bc1dece (patch) | |
tree | 3dd9a39e2b9db0d6e97e15c8b3bb7d595f2da612 /share/ruby/aserv.rb | |
parent | set svn:eol-style (diff) | |
download | opensim-SC-c0010e4940dd0ca067d469d8194be69b2bc1dece.zip opensim-SC-c0010e4940dd0ca067d469d8194be69b2bc1dece.tar.gz opensim-SC-c0010e4940dd0ca067d469d8194be69b2bc1dece.tar.bz2 opensim-SC-c0010e4940dd0ca067d469d8194be69b2bc1dece.tar.xz |
* Moved /branches/ruby to /trunk/share/ruby
Diffstat (limited to '')
-rw-r--r-- | share/ruby/aserv.rb | 35 |
1 files changed, 35 insertions, 0 deletions
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 @@ | |||
1 | require "webrick" | ||
2 | |||
3 | # | ||
4 | # Dummy asset server | ||
5 | # | ||
6 | |||
7 | class AssetServlet < WEBrick::HTTPServlet::AbstractServlet | ||
8 | def do_GET(req, res) | ||
9 | uuid = req.path.split("/")[2].downcase.gsub(/[^0-9a-f]+/, "") | ||
10 | if uuid.length == 32 | ||
11 | # length is correct | ||
12 | File.open("assets/#{uuid}/data") do |f| | ||
13 | res.body = f.read | ||
14 | end | ||
15 | end | ||
16 | # res["content-type"] = "text/plain" # or what do we set it to ? | ||
17 | end | ||
18 | def do_POST(req, res) | ||
19 | uuid = req.path.split("/")[2].downcase.gsub(/[^0-9a-f]+/, "") | ||
20 | if uuid.length == 32 | ||
21 | Dir.mkdir("assets/#{uuid}") | ||
22 | File.open("assets/#{uuid}/data", "wb") do |f| | ||
23 | f.write req.body | ||
24 | STDERR.print "Written #{req.body.length} bytes for uuid #{uuid}\n\n" | ||
25 | end | ||
26 | end | ||
27 | end | ||
28 | end | ||
29 | |||
30 | |||
31 | svr = WEBrick::HTTPServer.new(:Port=>8003) | ||
32 | svr.mount("/assets", AssetServlet, 5000000) | ||
33 | trap(:INT){ svr.shutdown } | ||
34 | svr.start | ||
35 | |||