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:
parent
bbc75ae306
commit
4d327641d9
2 changed files with 18 additions and 8 deletions
|
@ -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
|
||||
|
|
|
@ -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'},
|
||||
|
|
Loading…
Reference in a new issue