Skip to content

Commit

Permalink
Merge pull request #147 from fcheung/fix_content_encoding
Browse files Browse the repository at this point in the history
Fix blank content-encoding headers
  • Loading branch information
lanej committed Jul 8, 2015
2 parents b03235f + 0dee386 commit a48674e
Showing 1 changed file with 4 additions and 8 deletions.
12 changes: 4 additions & 8 deletions lib/fog/aws/storage.rb
Original file line number Diff line number Diff line change
Expand Up @@ -559,16 +559,12 @@ def request(params, &block)
params[:headers]['x-amz-date'] = date.to_iso8601_basic
if params[:body].respond_to?(:read)
# See http://docs.aws.amazon.com/AmazonS3/latest/API/sigv4-streaming.html
# We ignore the bit about setting the content-encoding to aws-chunked because
# this can cause s3 to serve files with a blank content encoding which causes problems with some CDNs
# AWS have confirmed that s3 can infer that the content-encoding is aws-chunked from the x-amz-content-sha256 header
#
params[:headers]['x-amz-content-sha256'] = 'STREAMING-AWS4-HMAC-SHA256-PAYLOAD'
params[:headers]['x-amz-decoded-content-length'] = params[:headers].delete 'Content-Length'

if params[:headers]['Content-Encoding'] && params[:headers]['Content-Encoding'].to_s.length > 0
encoding = "aws-chunked,#{params[:headers]['Content-Encoding']}"
else
encoding = "aws-chunked"
end

params[:headers]['Content-Encoding'] = encoding
else
params[:headers]['x-amz-content-sha256'] ||= Digest::SHA256.hexdigest(params[:body] || '')
end
Expand Down

0 comments on commit a48674e

Please sign in to comment.