Permalink
Browse files

Add custom headers support based on regexp

  • Loading branch information...
cfcosta committed Dec 4, 2012
1 parent 061f45b commit 643d82b2b3b98afd4bb0355a127339bb66a4c83e
Showing with 13 additions and 1 deletion.
  1. +2 −0 lib/asset_sync/config.rb
  2. +11 −1 lib/asset_sync/storage.rb
View
@@ -11,6 +11,7 @@ class Invalid < StandardError; end
attr_accessor :fail_silently
attr_accessor :always_upload
attr_accessor :ignored_files
+ attr_accessor :custom_headers
attr_accessor :prefix
attr_accessor :public_path
attr_accessor :enabled
@@ -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
View
@@ -148,10 +148,20 @@ def upload_file(f)
:content_encoding => 'gzip'
})
end
+
+ add_custom_headers(file)
+

This comment has been minimized.

Show comment
Hide comment
@juwalter

juwalter Dec 4, 2012

how about something like file = file.merge(custom_headers) ?

@juwalter

juwalter Dec 4, 2012

how about something like file = file.merge(custom_headers) ?

This comment has been minimized.

Show comment
Hide comment
@cfcosta

cfcosta Dec 4, 2012

Owner

Because there can be more than one matching rule for each file.

@cfcosta

cfcosta Dec 4, 2012

Owner

Because there can be more than one matching rule for each file.

log "Uploading: #{f}"
end
- file = bucket.files.create( file ) unless ignore
+ bucket.files.create(file) unless ignore
+ end
+
+ def add_custom_headers(file)
+ headers = config.custom_headers.select { |(key, _)| file[:key] =~ key }
+ return unless headers
+
+ headers.values.each { |h| file.merge! h }
end
def upload_files

0 comments on commit 643d82b

Please sign in to comment.