lib/fakes3/server.rb in fakes3-0.1.5 vs lib/fakes3/server.rb in fakes3-0.1.5.2

- old
+ new

@@ -85,14 +85,19 @@ return end response.status = 200 response['Content-Type'] = real_obj.content_type - content_length = File::Stat.new(real_obj.io.path).size - response['Etag'] = real_obj.md5 + stat = File::Stat.new(real_obj.io.path) + + response['Last-Modified'] = stat.mtime.iso8601() + response.header['ETag'] = "\"#{real_obj.md5}\"" response['Accept-Ranges'] = "bytes" + response['Last-Ranges'] = "bytes" + content_length = stat.size + # Added Range Query support if range = request.header["range"].first response.status = 206 if range =~ /bytes=(\d*)-(\d*)/ start = $1.to_i @@ -111,10 +116,11 @@ response.body = real_obj.io.read(bytes_to_read) return end end response['Content-Length'] = File::Stat.new(real_obj.io.path).size + response['Last-Modified'] = real_obj.modified_date if s_req.http_verb == 'HEAD' response.body = "" else response.body = real_obj.io end @@ -133,11 +139,11 @@ # Lazily create a bucket. TODO fix this to return the proper error bucket_obj = @store.create_bucket(s_req.bucket) end real_obj = @store.store_object(bucket_obj,s_req.object,s_req.webrick_request) - response['Etag'] = real_obj.md5 + response.header['ETag'] = "\"#{real_obj.md5}\"" when Request::CREATE_BUCKET @store.create_bucket(s_req.bucket) end response.status = 200 @@ -205,14 +211,11 @@ s_req.bucket = elems[0] else elems = path.split("/") end - if elems.size == 0 - # List buckets - s_req.type = Request::LIST_BUCKETS - elsif elems.size == 1 + if elems.size < 2 s_req.type = Request::LS_BUCKET s_req.query = query else if query["acl"] == "" s_req.type = Request::GET_ACL @@ -309,17 +312,18 @@ end end class Server - def initialize(port,store,hostname) + def initialize(address,port,store,hostname) + @address = address @port = port @store = store @hostname = hostname end def serve - @server = WEBrick::HTTPServer.new(:Port => @port) + @server = WEBrick::HTTPServer.new(:BindAddress => @address, :Port => @port) @server.mount "/", Servlet, @store,@hostname trap "INT" do @server.shutdown end @server.start end