Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP


Add ability to declare custom headers #120

wants to merge 1 commit into from

4 participants


As mentioned in my question #119, I wanted to ask about the ability to declare custom headers for short-lived assets. This is my first pull-request, so please bare with me.

The way I approached it is to allow to set a hash, where the key is the file name, and the value is a hash of headers. Please let me know if there is something else I can do.

@nambrot nambrot Added the option to specify custom headers on a per-file basis
* config.custom_headers defaults to empty Hash
* use the file name as a key to point to the header hash

Why this was not merged yet?


not sure, i currently use this on our production system (if that matters at all)


You are lacking tests, that makes it harder to merge.


Merged in #168 closing this one.

@davidjrice davidjrice closed this
@josephlord josephlord referenced this pull request from a commit in josephlord/asset_sync
@griffindy griffindy Added tests custom header addition
* building off the work here: rumblelabs#120
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Oct 28, 2012
  1. @nambrot

    Added the option to specify custom headers on a per-file basis

    nambrot authored
    * config.custom_headers defaults to empty Hash
    * use the file name as a key to point to the header hash
This page is out of date. Refresh to see the latest.
Showing with 13 additions and 0 deletions.
  1. +3 −0  lib/asset_sync/config.rb
  2. +10 −0 lib/asset_sync/storage.rb
3  lib/asset_sync/config.rb
@@ -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?
@@ -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")
10 lib/asset_sync/storage.rb
@@ -57,6 +57,10 @@ def always_upload_files { |f| File.join(self.config.assets_prefix, f) }
+ 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( + 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:
log "AssetSync: Syncing."
+ log files_with_custom_headers.to_json
delete_extra_remote_files unless keep_existing_remote_files?
log "AssetSync: Done."
Something went wrong with that request. Please try again.