1
0
Fork 0
mirror of https://github.com/fog/fog.git synced 2022-11-09 13:51:43 -05:00

more realistic mock etags, handle preconditions in s3 get_object mock

This commit is contained in:
Wesley Beary 2009-08-12 21:13:55 -07:00
parent bbc75ae306
commit 4d327641d9
2 changed files with 18 additions and 8 deletions

View file

@ -54,13 +54,23 @@ else
bucket = @data['Buckets'].select {|bucket| bucket['Name'] == bucket_name}.first
object = bucket['Contents'].select {|object| object['Key'] == object_name}.first
if object
response.status = 200
response.headers = {
'Content-Length' => object['Size'],
'ETag' => object['ETag'],
'Last-Modified' => object['LastModified']
}
response.body = object[:body]
if options['If-Match'] && options['If-Match'] != object['ETag']
response.status = 412
elsif options['If-Modified-Since'] && options['If-Modified-Since'] > Time.parse(object['LastModified'])
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['LastModified'])
response.status = 412
else
response.status = 200
response.headers = {
'Content-Length' => object['Size'],
'ETag' => object['ETag'],
'Last-Modified' => object['LastModified']
}
response.body = object[:body]
end
else
response.status = 404
end

View file

@ -56,7 +56,7 @@ else
bucket = @data['Buckets'].select {|bucket| bucket['Name'] == bucket_name}.first
bucket['Contents'] << {
:body => file[:body],
'ETag' => 'some_etag',
'ETag' => Digest::SHA1.hexdigest(rand.to_s)[0...32],
'Key' => object_name,
'LastModified' => Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000"),
'Owner' => { 'DisplayName' => 'owner', 'ID' => 'some_id'},