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

[aws&google] finish fixing headers in mocks

This commit is contained in:
geemus 2011-02-02 16:27:22 -08:00
parent 67d3bade8c
commit 96ca167eb6
8 changed files with 42 additions and 32 deletions

View file

@ -60,7 +60,7 @@ module Fog
target_bucket[:objects][target_object_name] = target_object
response.body = {
'ETag' => target_object['ETag'],
'LastModified' => Time.parse(target_object['LastModified'])
'LastModified' => Time.parse(target_object['Last-Modified'])
}
else
response.status = 404

View file

@ -72,11 +72,11 @@ module Fog
(options['prefix'] && object['Key'][0...options['prefix'].length] != options['prefix']) ||
(options['marker'] && object['Key'] <= options['marker'])
end.map do |object|
data = object.reject {|key, value| !['ETag', 'Key', 'LastModified', 'Size', 'StorageClass'].include?(key)}
data = object.reject {|key, value| !['ETag', 'Key', 'StorageClass'].include?(key)}
data.merge!({
'LastModified' => Time.parse(data['LastModified']),
'LastModified' => Time.parse(object['Last-Modified']),
'Owner' => bucket['Owner'],
'Size' => data['Size'].to_i
'Size' => object['Content-Length'].to_i
})
data
end

View file

@ -68,15 +68,20 @@ module Fog
if (bucket = @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['LastModified'])
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['LastModified'])
elsif options['If-Unmodified-Since'] && options['If-Unmodified-Since'] < Time.parse(object['Last-Modified'])
response.status = 412
else
response.status = 200
response.headers = object.reject {|key, value| key == :body}
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

View file

@ -64,13 +64,13 @@ module Fog
if (bucket = @data[:buckets][bucket_name])
response.status = 200
object = {
:body => data[:body],
'Content-Type' => options['Content-Type'] || data[:headers]['Content-Type'],
'ETag' => Fog::AWS::Mock.etag,
'Key' => object_name,
'LastModified' => Fog::Time.now.to_date_header,
'Size' => options['Content-Length'] || data[:headers]['Content-Length'],
'StorageClass' => options['x-amz-storage-class'] || 'STANDARD'
:body => data[:body],
'Content-Type' => options['Content-Type'] || data[:headers]['Content-Type'],
'ETag' => Fog::AWS::Mock.etag,
'Key' => object_name,
'Last-Modified' => Fog::Time.now.to_date_header,
'Content-Length' => options['Content-Length'] || data[:headers]['Content-Length'],
'StorageClass' => options['x-amz-storage-class'] || 'STANDARD'
}
for key, value in options
@ -82,10 +82,10 @@ module Fog
bucket[:objects][object_name] = object
response.headers = {
'Content-Length' => object['Size'],
'Content-Length' => object['Content-Length'],
'Content-Type' => object['Content-Type'],
'ETag' => object['ETag'],
'Last-Modified' => object['LastModified']
'Last-Modified' => object['Last-Modified']
}
else
response.status = 404

View file

@ -56,7 +56,7 @@ module Fog
target_bucket[:objects][target_object_name] = target_object
response.body = {
'ETag' => target_object['ETag'],
'LastModified' => Time.parse(target_object['LastModified'])
'LastModified' => Time.parse(target_object['Last-Modified'])
}
else
response.status = 404

View file

@ -69,11 +69,11 @@ module Fog
(options['prefix'] && object['Key'][0...options['prefix'].length] != options['prefix']) ||
(options['marker'] && object['Key'] <= options['marker'])
end.map do |object|
data = object.reject {|key, value| !['ETag', 'Key', 'LastModified', 'Size', 'StorageClass'].include?(key)}
data = object.reject {|key, value| !['ETag', 'Key', 'StorageClass'].include?(key)}
data.merge!({
'LastModified' => Time.parse(data['LastModified']),
'LastModified' => Time.parse(object['Last-Modified']),
'Owner' => bucket['Owner'],
'Size' => data['Size'].to_i
'Size' => object['Content-Length'].to_i
})
data
end

View file

@ -65,15 +65,20 @@ module Fog
if (bucket = @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['LastModified'])
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['LastModified'])
elsif options['If-Unmodified-Since'] && options['If-Unmodified-Since'] < Time.parse(object['Last-Modified'])
response.status = 412
else
response.status = 200
response.headers = object.reject {|key, value| key == :body}
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-goog-meta-/
response.headers[key] = value
end
end
unless block_given?
response.body = object[:body]
else

View file

@ -58,13 +58,13 @@ module Fog
if (bucket = @data[:buckets][bucket_name])
response.status = 200
object = {
:body => data[:body],
'Content-Type' => options['Content-Type'] || data[:headers]['Content-Type'],
'ETag' => Fog::Google::Mock.etag,
'Key' => object_name,
'LastModified' => Fog::Time.now.to_date_header,
'Size' => options['Content-Length'] || data[:headers]['Content-Length'],
'StorageClass' => 'STANDARD'
:body => data[:body],
'Content-Type' => options['Content-Type'] || data[:headers]['Content-Type'],
'ETag' => Fog::Google::Mock.etag,
'Key' => object_name,
'Last-Modified' => Fog::Time.now.to_date_header,
'Content-Length' => options['Content-Length'] || data[:headers]['Content-Length'],
'StorageClass' => 'STANDARD'
}
for key, value in options
@ -76,10 +76,10 @@ module Fog
bucket[:objects][object_name] = object
response.headers = {
'Content-Length' => object['Size'],
'Content-Length' => object['Content-Length'],
'Content-Type' => object['Content-Type'],
'ETag' => object['ETag'],
'Last-Modified' => object['LastModified']
'Last-Modified' => object['Last-Modified']
}
else
response.status = 404