File tree Expand file tree Collapse file tree 3 files changed +33
-1
lines changed
Expand file tree Collapse file tree 3 files changed +33
-1
lines changed Original file line number Diff line number Diff line change @@ -237,7 +237,7 @@ def validate(entry)
237237
238238 entry = entry . dup
239239 entry . headers . delete ( 'date' )
240- %w[ Date expires cache-control etag last-modified ] . each do |name |
240+ %w[ Date expires cache-control etag last-modified ] . concat ( transfer_headers ) . each do |name |
241241 next unless value = response . headers [ name ]
242242 entry . headers [ name ] = value
243243 end
Original file line number Diff line number Diff line change @@ -86,6 +86,13 @@ def option_name(key)
8686 # Default: ['set-cookie']
8787 option_accessor :ignore_headers
8888
89+ # Set of response headers that are transferred from the backend response
90+ # onto the cache entry when validating a cached entity (after receiving a
91+ # 304 response from the backend) before sending it to the client.
92+ #
93+ # Default: []
94+ option_accessor :transfer_headers
95+
8996 # Set of request headers that trigger "private" cache-control behavior
9097 # on responses that don't explicitly state whether the response is
9198 # public or private via a cache-control directive. Applications that use
@@ -149,6 +156,7 @@ def initialize_options(options={})
149156 'rack-cache.entitystore' => 'heap:/' ,
150157 'rack-cache.default_ttl' => 0 ,
151158 'rack-cache.ignore_headers' => [ 'set-cookie' ] ,
159+ 'rack-cache.transfer_headers' => [ ] ,
152160 'rack-cache.private_headers' => [ 'Authorization' , 'Cookie' ] ,
153161 'rack-cache.allow_reload' => false ,
154162 'rack-cache.allow_revalidate' => false ,
Original file line number Diff line number Diff line change 776776 cache . trace . wont_include :miss
777777 end
778778
779+ it 'includes specified additional headers from the backend in responses to the client' do
780+ count = 0
781+ respond_with do |req , res |
782+ count += 1
783+ res [ 'ETAG' ] = '"12345"'
784+ res [ 'unique-snowflake' ] = '"so-special"'
785+ res . status = ( count == 1 ) ? 200 : 304
786+ end
787+
788+ get '/' , 'rack-cache.transfer_headers' => [ 'unique-snowflake' ]
789+ assert app . called?
790+ assert response . ok?
791+ response . headers . must_include 'unique-snowflake'
792+ response [ 'unique-snowflake' ] . must_equal '"so-special"'
793+ cache . trace . must_include :miss
794+
795+ get '/' , 'rack-cache.transfer_headers' => [ 'unique-snowflake' ]
796+ assert app . called?
797+ assert response . ok?
798+ response . headers . must_include 'unique-snowflake'
799+ response [ 'unique-snowflake' ] . must_equal '"so-special"'
800+ cache . trace . must_include :valid
801+ end
802+
779803 it 'replaces cached responses when validation results in non-304 response' do
780804 timestamp = Time . now . httpdate
781805 count = 0
You can’t perform that action at this time.
0 commit comments