mirror of
https://github.com/fog/fog.git
synced 2022-11-09 13:51:43 -05:00
[storage|aws] more precise mocked get_object
fixes to differentiate between missing bucket and object
This commit is contained in:
parent
72b66750c4
commit
da098b6397
1 changed files with 32 additions and 25 deletions
|
@ -65,37 +65,44 @@ module Fog
|
|||
raise ArgumentError.new('object_name is required')
|
||||
end
|
||||
response = Excon::Response.new
|
||||
if (bucket = self.data[:buckets][bucket_name]) && (object = bucket[:objects][object_name])
|
||||
if options['If-Match'] && options['If-Match'] != object['ETag']
|
||||
response.status = 412
|
||||
elsif options['If-Modified-Since'] && options['If-Modified-Since'] > Time.parse(object['Last-Modified'])
|
||||
response.status = 304
|
||||
elsif options['If-None-Match'] && options['If-None-Match'] == object['ETag']
|
||||
response.status = 304
|
||||
elsif options['If-Unmodified-Since'] && options['If-Unmodified-Since'] < Time.parse(object['Last-Modified'])
|
||||
response.status = 412
|
||||
else
|
||||
response.status = 200
|
||||
for key, value in object
|
||||
case key
|
||||
when 'Cache-Control', 'Content-Disposition', 'Content-Encoding', 'Content-Length', 'Content-MD5', 'Content-Type', 'ETag', 'Expires', 'Last-Modified', /^x-amz-meta-/
|
||||
response.headers[key] = value
|
||||
end
|
||||
end
|
||||
unless block_given?
|
||||
response.body = object[:body]
|
||||
if (bucket = self.data[:buckets][bucket_name])
|
||||
if (object = bucket[:objects][object_name])
|
||||
if options['If-Match'] && options['If-Match'] != object['ETag']
|
||||
response.status = 412
|
||||
elsif options['If-Modified-Since'] && options['If-Modified-Since'] > Time.parse(object['Last-Modified'])
|
||||
response.status = 304
|
||||
elsif options['If-None-Match'] && options['If-None-Match'] == object['ETag']
|
||||
response.status = 304
|
||||
elsif options['If-Unmodified-Since'] && options['If-Unmodified-Since'] < Time.parse(object['Last-Modified'])
|
||||
response.status = 412
|
||||
else
|
||||
data = StringIO.new(object[:body])
|
||||
remaining = data.length
|
||||
while remaining > 0
|
||||
chunk = data.read([remaining, Excon::CHUNK_SIZE].min)
|
||||
block.call(chunk)
|
||||
remaining -= Excon::CHUNK_SIZE
|
||||
response.status = 200
|
||||
for key, value in object
|
||||
case key
|
||||
when 'Cache-Control', 'Content-Disposition', 'Content-Encoding', 'Content-Length', 'Content-MD5', 'Content-Type', 'ETag', 'Expires', 'Last-Modified', /^x-amz-meta-/
|
||||
response.headers[key] = value
|
||||
end
|
||||
end
|
||||
unless block_given?
|
||||
response.body = object[:body]
|
||||
else
|
||||
data = StringIO.new(object[:body])
|
||||
remaining = data.length
|
||||
while remaining > 0
|
||||
chunk = data.read([remaining, Excon::CHUNK_SIZE].min)
|
||||
block.call(chunk)
|
||||
remaining -= Excon::CHUNK_SIZE
|
||||
end
|
||||
end
|
||||
end
|
||||
else
|
||||
response.status = 404
|
||||
response.body = "...<Code>NoSuchKey<\/Code>..."
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
else
|
||||
response.status = 404
|
||||
response.body = "...<Code>NoSuchBucket</Code>..."
|
||||
raise(Excon::Errors.status_error({:expects => 200}, response))
|
||||
end
|
||||
response
|
||||
|
|
Loading…
Reference in a new issue