Add ability to declare custom headers #120

Closed
wants to merge 1 commit into
from
View
@@ -14,6 +14,7 @@ class Invalid < StandardError; end
attr_accessor :prefix
attr_accessor :public_path
attr_accessor :enabled
+ attr_accessor :custom_headers
# FOG configuration
attr_accessor :fog_provider # Currently Supported ['AWS', 'Rackspace']
@@ -49,6 +50,7 @@ def initialize
self.fail_silently = false
self.always_upload = []
self.ignored_files = []
+ self.custom_headers = {}
self.enabled = true
load_yml! if defined?(Rails) && yml_exists?
end
@@ -126,6 +128,7 @@ def load_yml!
self.fail_silently = yml["fail_silently"] if yml.has_key?("fail_silently")
self.always_upload = yml["always_upload"] if yml.has_key?("always_upload")
self.ignored_files = yml["ignored_files"] if yml.has_key?("ignored_files")
+ self.custom_headers = yml["custom_headers"] if yml.has_key?("custom_headers")
# TODO deprecate the other old style config settings. FML.
self.aws_access_key_id = yml["aws_access_key"] if yml.has_key?("aws_access_key")
View
@@ -57,6 +57,10 @@ def always_upload_files
self.config.always_upload.map { |f| File.join(self.config.assets_prefix, f) }
end
+ def files_with_custom_headers
+ self.config.custom_headers.inject({}) { |h,(k, v)| h[File.join(self.config.assets_prefix, k)] = v; h; }
+ end
+
def get_local_files
if self.config.manifest
if File.exists?(self.config.manifest_path)
@@ -115,6 +119,11 @@ def upload_file(f)
:expires => CGI.rfc1123_date(Time.now + one_year),
:content_type => mime
}
+ # overwrite headers if applicable, you probably shouldn't specific key/body, but cache-control headers etc.
+ if files_with_custom_headers.has_key? f
+ file.merge! files_with_custom_headers[f]
+ log "Overwriting #{f} with custom headers #{files_with_custom_headers[f].to_s}"
+ end
gzipped = "#{path}/#{f}.gz"
ignore = false
@@ -170,6 +179,7 @@ def upload_files
def sync
# fixes: https://github.com/rumblelabs/asset_sync/issues/19
log "AssetSync: Syncing."
+ log files_with_custom_headers.to_json
upload_files
delete_extra_remote_files unless keep_existing_remote_files?
log "AssetSync: Done."