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

[fog|time] add date header formatting that is non-localized

This commit is contained in:
geemus 2011-01-28 15:33:35 -08:00
parent 242595e919
commit d055ac1ec9
12 changed files with 36 additions and 30 deletions

View file

@ -70,7 +70,7 @@ module Fog
headers = {
'Content-Type' => 'application/x-www-form-urlencoded',
'Date' => Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
'Date' => Fog::Time.now.to_date_header
}
#AWS3-HTTPS AWSAccessKeyId=<Your AWS Access Key ID>, Algorithm=HmacSHA256, Signature=<Signature>

View file

@ -98,7 +98,7 @@ module Fog
def request(params, &block)
params[:headers] ||= {}
params[:headers]['Date'] = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
params[:headers]['Date'] = Fog::Time.now.to_date_header
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature(params)}"
params[:path] = "/#{@version}/#{params[:path]}"
@connection.request(params, &block)

View file

@ -1,21 +1,27 @@
module Fog
class Time < ::Time
class << self
def now
::Time.now - offset
end
def now=(new_now)
old_now = ::Time.now
@offset = old_now - new_now
new_now
end
def offset
@offset ||= 0
end
DAYS = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat']
MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec']
def self.now
at((::Time.now - offset).to_i)
end
def self.now=(new_now)
old_now = ::Time.now
@offset = old_now - new_now
new_now
end
def self.offset
@offset ||= 0
end
def to_date_header
now = self.class.now.utc
now.strftime("#{DAYS[now.wday]}, %d #{MONTHS[now.month - 1]} %Y %H:%M:%S +0000")
end
end
end
end

View file

@ -103,7 +103,7 @@ module Fog
def request(params, &block)
params[:headers] ||= {}
params[:headers]['Date'] = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
params[:headers]['Date'] = Fog::Time.now.to_date_header
params[:headers]['X-Amzn-Authorization'] = "AWS3-HTTPS AWSAccessKeyId=#{@aws_access_key_id},Algorithm=HmacSHA1,Signature=#{signature(params)}"
params[:path] = "/#{@version}/#{params[:path]}"
@connection.request(params, &block)

View file

@ -289,7 +289,7 @@ module Fog
private
def request(params, &block)
params[:headers]['Date'] = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
params[:headers]['Date'] = Fog::Time.now.to_date_header
params[:headers]['Authorization'] = "AWS #{@aws_access_key_id}:#{signature(params)}"
params[:expects] = [307, *params[:expects]].flatten
# FIXME: ToHashParser should make this not needed

View file

@ -212,7 +212,7 @@ module Fog
private
def request(params, &block)
params[:headers]['Date'] = Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000")
params[:headers]['Date'] = Fog::Time.now.to_date_header
params[:headers]['Authorization'] = "GOOG1 #{@google_storage_access_key_id}:#{signature(params)}"
response = @connection.request(params, &block)

View file

@ -39,8 +39,8 @@ module Fog
query = {'versionId' => version_id}
end
headers = {}
headers['If-Modified-Since'] = options['If-Modified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
headers['If-Unmodified-Since'] = options['If-Unmodified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
headers['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header if options['If-Modified-Since']
headers['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header if options['If-Modified-Since']
headers.merge!(options)
request({
:expects => 200,

View file

@ -39,8 +39,8 @@ module Fog
query = {'versionId' => version_id}
end
headers = {}
headers['If-Modified-Since'] = options['If-Modified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
headers['If-Unmodified-Since'] = options['If-Unmodified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
headers['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header if options['If-Modified-Since']
headers['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header if options['If-Modified-Since']
headers.merge!(options)
request({
:expects => 200,

View file

@ -67,7 +67,7 @@ module Fog
'Content-Type' => data[:headers]['Content-Type'],
'ETag' => Fog::AWS::Mock.etag,
'Key' => object_name,
'LastModified' => Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000"),
'LastModified' => Fog::Time.now.to_date_header,
'Size' => data[:headers]['Content-Length'],
'StorageClass' => 'STANDARD'
}

View file

@ -36,8 +36,8 @@ module Fog
query = {'versionId' => version_id}
end
headers = {}
headers['If-Modified-Since'] = options['If-Modified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
headers['If-Unmodified-Since'] = options['If-Unmodified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
headers['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header if options['If-Modified-Since']
headers['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header if options['If-Modified-Since']
headers.merge!(options)
request({
:expects => 200,

View file

@ -35,8 +35,8 @@ module Fog
query = {'versionId' => version_id}
end
headers = {}
headers['If-Modified-Since'] = options['If-Modified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
headers['If-Unmodified-Since'] = options['If-Unmodified-Since'].utc.strftime("%a, %d %b %Y %H:%M:%S +0000") if options['If-Modified-Since']
headers['If-Modified-Since'] = Fog::Time.at(options['If-Modified-Since'].to_i).to_date_header if options['If-Modified-Since']
headers['If-Unmodified-Since'] = Fog::Time.at(options['If-Unmodified-Since'].to_i).to_date_header if options['If-Modified-Since']
headers.merge!(options)
request({
:expects => 200,

View file

@ -62,7 +62,7 @@ module Fog
'Content-Type' => data[:headers]['Content-Type'],
'ETag' => Fog::Google::Mock.etag,
'Key' => object_name,
'LastModified' => Time.now.utc.strftime("%a, %d %b %Y %H:%M:%S +0000"),
'LastModified' => Fog::Time.now.to_date_header,
'Size' => data[:headers]['Content-Length'],
'StorageClass' => 'STANDARD'
}