@@ -146,16 +146,35 @@ describe('headers', () => {
146
146
describe ( 'setCacheControlHeaders' , ( ) => {
147
147
const defaultUrl = 'https://example.com'
148
148
149
- test ( 'should not set any headers if "cache-control" is not set' , ( ) => {
149
+ test ( 'should not set any headers if "cache-control" is not set and "requestContext.usedFsRead" is not truthy ' , ( ) => {
150
150
const headers = new Headers ( )
151
151
const request = new Request ( defaultUrl )
152
152
vi . spyOn ( headers , 'set' )
153
153
154
- setCacheControlHeaders ( headers , request )
154
+ setCacheControlHeaders ( headers , request , { } )
155
155
156
156
expect ( headers . set ) . toHaveBeenCalledTimes ( 0 )
157
157
} )
158
158
159
+ test ( 'should set permanent "netlify-cdn-cache-control" if "cache-control" is not set and "requestContext.usedFsRead" is truthy' , ( ) => {
160
+ const headers = new Headers ( )
161
+ const request = new Request ( defaultUrl )
162
+ vi . spyOn ( headers , 'set' )
163
+
164
+ setCacheControlHeaders ( headers , request , { usedFsRead : true } )
165
+
166
+ expect ( headers . set ) . toHaveBeenNthCalledWith (
167
+ 1 ,
168
+ 'cache-control' ,
169
+ 'public, max-age=0, must-revalidate' ,
170
+ )
171
+ expect ( headers . set ) . toHaveBeenNthCalledWith (
172
+ 2 ,
173
+ 'netlify-cdn-cache-control' ,
174
+ 'max-age=31536000' ,
175
+ )
176
+ } )
177
+
159
178
test ( 'should not set any headers if "cache-control" is set and "cdn-cache-control" is present' , ( ) => {
160
179
const givenHeaders = {
161
180
'cache-control' : 'public, max-age=0, must-revalidate' ,
@@ -165,7 +184,7 @@ describe('headers', () => {
165
184
const request = new Request ( defaultUrl )
166
185
vi . spyOn ( headers , 'set' )
167
186
168
- setCacheControlHeaders ( headers , request )
187
+ setCacheControlHeaders ( headers , request , { } )
169
188
170
189
expect ( headers . set ) . toHaveBeenCalledTimes ( 0 )
171
190
} )
@@ -179,7 +198,7 @@ describe('headers', () => {
179
198
const request = new Request ( defaultUrl )
180
199
vi . spyOn ( headers , 'set' )
181
200
182
- setCacheControlHeaders ( headers , request )
201
+ setCacheControlHeaders ( headers , request , { } )
183
202
184
203
expect ( headers . set ) . toHaveBeenCalledTimes ( 0 )
185
204
} )
@@ -192,7 +211,7 @@ describe('headers', () => {
192
211
const request = new Request ( defaultUrl )
193
212
vi . spyOn ( headers , 'set' )
194
213
195
- setCacheControlHeaders ( headers , request )
214
+ setCacheControlHeaders ( headers , request , { } )
196
215
197
216
expect ( headers . set ) . toHaveBeenNthCalledWith (
198
217
1 ,
@@ -214,7 +233,7 @@ describe('headers', () => {
214
233
const request = new Request ( defaultUrl , { method : 'HEAD' } )
215
234
vi . spyOn ( headers , 'set' )
216
235
217
- setCacheControlHeaders ( headers , request )
236
+ setCacheControlHeaders ( headers , request , { } )
218
237
219
238
expect ( headers . set ) . toHaveBeenNthCalledWith (
220
239
1 ,
@@ -236,7 +255,7 @@ describe('headers', () => {
236
255
const request = new Request ( defaultUrl , { method : 'POST' } )
237
256
vi . spyOn ( headers , 'set' )
238
257
239
- setCacheControlHeaders ( headers , request )
258
+ setCacheControlHeaders ( headers , request , { } )
240
259
241
260
expect ( headers . set ) . toHaveBeenCalledTimes ( 0 )
242
261
} )
@@ -249,7 +268,7 @@ describe('headers', () => {
249
268
const request = new Request ( defaultUrl )
250
269
vi . spyOn ( headers , 'set' )
251
270
252
- setCacheControlHeaders ( headers , request )
271
+ setCacheControlHeaders ( headers , request , { } )
253
272
254
273
expect ( headers . set ) . toHaveBeenNthCalledWith ( 1 , 'cache-control' , 'public' )
255
274
expect ( headers . set ) . toHaveBeenNthCalledWith (
@@ -267,7 +286,7 @@ describe('headers', () => {
267
286
const request = new Request ( defaultUrl )
268
287
vi . spyOn ( headers , 'set' )
269
288
270
- setCacheControlHeaders ( headers , request )
289
+ setCacheControlHeaders ( headers , request , { } )
271
290
272
291
expect ( headers . set ) . toHaveBeenNthCalledWith ( 1 , 'cache-control' , 'max-age=604800' )
273
292
expect ( headers . set ) . toHaveBeenNthCalledWith (
@@ -285,7 +304,7 @@ describe('headers', () => {
285
304
const request = new Request ( defaultUrl )
286
305
vi . spyOn ( headers , 'set' )
287
306
288
- setCacheControlHeaders ( headers , request )
307
+ setCacheControlHeaders ( headers , request , { } )
289
308
290
309
expect ( headers . set ) . toHaveBeenNthCalledWith (
291
310
1 ,
0 commit comments