lib/nightcrawler_swift/upload.rb in nightcrawler_swift-0.2.3 vs lib/nightcrawler_swift/upload.rb in nightcrawler_swift-0.3.0

- old
+ new

@@ -1,10 +1,16 @@ +require 'digest' + module NightcrawlerSwift class Upload < Command def execute path, file content_type = MultiMime.by_file(file).content_type - response = put "#{connection.upload_url}/#{path}", body: file.read, headers: {content_type: content_type} + content = file.read + etag = '"%s"' % Digest::MD5.new.update(content).hexdigest + headers = {etag: etag, content_type: content_type} + headers.merge!({cache_control: "max-age=#{connection.opts.max_age}"}) if connection.opts.max_age + response = put "#{connection.upload_url}/#{path}", body: content, headers: headers [200, 201].include?(response.code) end end end