50
50
* headers can be controlled via the {@link #setCacheSeconds "cacheSeconds"}
51
51
* and {@link #setCacheControl "cacheControl"} properties.
52
52
*
53
- * <p><b>NOTE:</b> As of Spring 4.2, this generator's default behavior changed when
54
- * using only {@link #setCacheSeconds}, sending HTTP response headers that are in line
55
- * with current browsers and proxies implementations (i.e. no HTTP 1.0 headers anymore)
56
- * Reverting to the previous behavior can be easily done by using one of the newly
57
- * deprecated methods {@link #setUseExpiresHeader}, {@link #setUseCacheControlHeader},
58
- * {@link #setUseCacheControlNoStore} or {@link #setAlwaysMustRevalidate}.
59
- *
60
53
* @author Rod Johnson
61
54
* @author Juergen Hoeller
62
55
* @author Brian Clozel
@@ -76,10 +69,6 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
76
69
/** HTTP method "POST". */
77
70
public static final String METHOD_POST = "POST" ;
78
71
79
- private static final String HEADER_PRAGMA = "Pragma" ;
80
-
81
- private static final String HEADER_EXPIRES = "Expires" ;
82
-
83
72
protected static final String HEADER_CACHE_CONTROL = "Cache-Control" ;
84
73
85
74
@@ -101,20 +90,6 @@ public abstract class WebContentGenerator extends WebApplicationObjectSupport {
101
90
private String [] varyByRequestHeaders ;
102
91
103
92
104
- // deprecated fields
105
-
106
- /** Use HTTP 1.0 expires header? */
107
- private boolean useExpiresHeader = false ;
108
-
109
- /** Use HTTP 1.1 cache-control header? */
110
- private boolean useCacheControlHeader = true ;
111
-
112
- /** Use HTTP 1.1 cache-control header value "no-store"? */
113
- private boolean useCacheControlNoStore = true ;
114
-
115
- private boolean alwaysMustRevalidate = false ;
116
-
117
-
118
93
/**
119
94
* Create a new WebContentGenerator which supports
120
95
* HTTP methods GET, HEAD and POST by default.
@@ -284,90 +259,6 @@ public final String[] getVaryByRequestHeaders() {
284
259
return this .varyByRequestHeaders ;
285
260
}
286
261
287
- /**
288
- * Set whether to use the HTTP 1.0 expires header. Default is "false",
289
- * as of 4.2.
290
- * <p>Note: Cache headers will only get applied if caching is enabled
291
- * (or explicitly prevented) for the current request.
292
- * @deprecated as of 4.2, since going forward, the HTTP 1.1 cache-control
293
- * header will be required, with the HTTP 1.0 headers disappearing
294
- */
295
- @ Deprecated
296
- public final void setUseExpiresHeader (boolean useExpiresHeader ) {
297
- this .useExpiresHeader = useExpiresHeader ;
298
- }
299
-
300
- /**
301
- * Return whether the HTTP 1.0 expires header is used.
302
- * @deprecated as of 4.2, in favor of {@link #getCacheControl()}
303
- */
304
- @ Deprecated
305
- public final boolean isUseExpiresHeader () {
306
- return this .useExpiresHeader ;
307
- }
308
-
309
- /**
310
- * Set whether to use the HTTP 1.1 cache-control header. Default is "true".
311
- * <p>Note: Cache headers will only get applied if caching is enabled
312
- * (or explicitly prevented) for the current request.
313
- * @deprecated as of 4.2, since going forward, the HTTP 1.1 cache-control
314
- * header will be required, with the HTTP 1.0 headers disappearing
315
- */
316
- @ Deprecated
317
- public final void setUseCacheControlHeader (boolean useCacheControlHeader ) {
318
- this .useCacheControlHeader = useCacheControlHeader ;
319
- }
320
-
321
- /**
322
- * Return whether the HTTP 1.1 cache-control header is used.
323
- * @deprecated as of 4.2, in favor of {@link #getCacheControl()}
324
- */
325
- @ Deprecated
326
- public final boolean isUseCacheControlHeader () {
327
- return this .useCacheControlHeader ;
328
- }
329
-
330
- /**
331
- * Set whether to use the HTTP 1.1 cache-control header value "no-store"
332
- * when preventing caching. Default is "true".
333
- * @deprecated as of 4.2, in favor of {@link #setCacheControl}
334
- */
335
- @ Deprecated
336
- public final void setUseCacheControlNoStore (boolean useCacheControlNoStore ) {
337
- this .useCacheControlNoStore = useCacheControlNoStore ;
338
- }
339
-
340
- /**
341
- * Return whether the HTTP 1.1 cache-control header value "no-store" is used.
342
- * @deprecated as of 4.2, in favor of {@link #getCacheControl()}
343
- */
344
- @ Deprecated
345
- public final boolean isUseCacheControlNoStore () {
346
- return this .useCacheControlNoStore ;
347
- }
348
-
349
- /**
350
- * An option to add 'must-revalidate' to every Cache-Control header.
351
- * This may be useful with annotated controller methods, which can
352
- * programmatically do a last-modified calculation as described in
353
- * {@link org.springframework.web.context.request.WebRequest#checkNotModified(long)}.
354
- * <p>Default is "false".
355
- * @deprecated as of 4.2, in favor of {@link #setCacheControl}
356
- */
357
- @ Deprecated
358
- public final void setAlwaysMustRevalidate (boolean mustRevalidate ) {
359
- this .alwaysMustRevalidate = mustRevalidate ;
360
- }
361
-
362
- /**
363
- * Return whether 'must-revalidate' is added to every Cache-Control header.
364
- * @deprecated as of 4.2, in favor of {@link #getCacheControl()}
365
- */
366
- @ Deprecated
367
- public final boolean isAlwaysMustRevalidate () {
368
- return this .alwaysMustRevalidate ;
369
- }
370
-
371
262
372
263
/**
373
264
* Check the given request for supported methods and a required session, if any.
@@ -425,15 +316,6 @@ protected final void applyCacheControl(HttpServletResponse response, CacheContro
425
316
if (ccValue != null ) {
426
317
// Set computed HTTP 1.1 Cache-Control header
427
318
response .setHeader (HEADER_CACHE_CONTROL , ccValue );
428
-
429
- if (response .containsHeader (HEADER_PRAGMA )) {
430
- // Reset HTTP 1.0 Pragma header if present
431
- response .setHeader (HEADER_PRAGMA , "" );
432
- }
433
- if (response .containsHeader (HEADER_EXPIRES )) {
434
- // Reset HTTP 1.0 Expires header if present
435
- response .setHeader (HEADER_EXPIRES , "" );
436
- }
437
319
}
438
320
}
439
321
@@ -446,33 +328,18 @@ protected final void applyCacheControl(HttpServletResponse response, CacheContro
446
328
* @param cacheSeconds positive number of seconds into the future that the
447
329
* response should be cacheable for, 0 to prevent caching
448
330
*/
449
- @ SuppressWarnings ("deprecation" )
450
331
protected final void applyCacheSeconds (HttpServletResponse response , int cacheSeconds ) {
451
- if (this .useExpiresHeader || !this .useCacheControlHeader ) {
452
- // Deprecated HTTP 1.0 cache behavior, as in previous Spring versions
453
- if (cacheSeconds > 0 ) {
454
- cacheForSeconds (response , cacheSeconds );
455
- }
456
- else if (cacheSeconds == 0 ) {
457
- preventCaching (response );
458
- }
332
+ CacheControl cControl ;
333
+ if (cacheSeconds > 0 ) {
334
+ cControl = CacheControl .maxAge (cacheSeconds , TimeUnit .SECONDS );
335
+ }
336
+ else if (cacheSeconds == 0 ) {
337
+ cControl = CacheControl .noStore ();
459
338
}
460
339
else {
461
- CacheControl cControl ;
462
- if (cacheSeconds > 0 ) {
463
- cControl = CacheControl .maxAge (cacheSeconds , TimeUnit .SECONDS );
464
- if (this .alwaysMustRevalidate ) {
465
- cControl = cControl .mustRevalidate ();
466
- }
467
- }
468
- else if (cacheSeconds == 0 ) {
469
- cControl = (this .useCacheControlNoStore ? CacheControl .noStore () : CacheControl .noCache ());
470
- }
471
- else {
472
- cControl = CacheControl .empty ();
473
- }
474
- applyCacheControl (response , cControl );
340
+ cControl = CacheControl .empty ();
475
341
}
342
+ applyCacheControl (response , cControl );
476
343
}
477
344
478
345
@@ -493,105 +360,6 @@ protected final void checkAndPrepare(
493
360
applyCacheSeconds (response , cacheSeconds );
494
361
}
495
362
496
- /**
497
- * Apply the given cache seconds and generate respective HTTP headers.
498
- * <p>That is, allow caching for the given number of seconds in the
499
- * case of a positive value, prevent caching if given a 0 value, else
500
- * do nothing (i.e. leave caching to the client).
501
- * @param response the current HTTP response
502
- * @param cacheSeconds the (positive) number of seconds into the future
503
- * that the response should be cacheable for; 0 to prevent caching; and
504
- * a negative value to leave caching to the client.
505
- * @param mustRevalidate whether the client should revalidate the resource
506
- * (typically only necessary for controllers with last-modified support)
507
- * @deprecated as of 4.2, in favor of {@link #applyCacheControl}
508
- */
509
- @ Deprecated
510
- protected final void applyCacheSeconds (HttpServletResponse response , int cacheSeconds , boolean mustRevalidate ) {
511
- if (cacheSeconds > 0 ) {
512
- cacheForSeconds (response , cacheSeconds , mustRevalidate );
513
- }
514
- else if (cacheSeconds == 0 ) {
515
- preventCaching (response );
516
- }
517
- }
518
-
519
- /**
520
- * Set HTTP headers to allow caching for the given number of seconds.
521
- * Does not tell the browser to revalidate the resource.
522
- * @param response current HTTP response
523
- * @param seconds number of seconds into the future that the response
524
- * should be cacheable for
525
- * @deprecated as of 4.2, in favor of {@link #applyCacheControl}
526
- */
527
- @ Deprecated
528
- protected final void cacheForSeconds (HttpServletResponse response , int seconds ) {
529
- cacheForSeconds (response , seconds , false );
530
- }
531
-
532
- /**
533
- * Set HTTP headers to allow caching for the given number of seconds.
534
- * Tells the browser to revalidate the resource if mustRevalidate is
535
- * {@code true}.
536
- * @param response the current HTTP response
537
- * @param seconds number of seconds into the future that the response
538
- * should be cacheable for
539
- * @param mustRevalidate whether the client should revalidate the resource
540
- * (typically only necessary for controllers with last-modified support)
541
- * @deprecated as of 4.2, in favor of {@link #applyCacheControl}
542
- */
543
- @ Deprecated
544
- protected final void cacheForSeconds (HttpServletResponse response , int seconds , boolean mustRevalidate ) {
545
- if (this .useExpiresHeader ) {
546
- // HTTP 1.0 header
547
- response .setDateHeader (HEADER_EXPIRES , System .currentTimeMillis () + seconds * 1000L );
548
- }
549
- else if (response .containsHeader (HEADER_EXPIRES )) {
550
- // Reset HTTP 1.0 Expires header if present
551
- response .setHeader (HEADER_EXPIRES , "" );
552
- }
553
-
554
- if (this .useCacheControlHeader ) {
555
- // HTTP 1.1 header
556
- String headerValue = "max-age=" + seconds ;
557
- if (mustRevalidate || this .alwaysMustRevalidate ) {
558
- headerValue += ", must-revalidate" ;
559
- }
560
- response .setHeader (HEADER_CACHE_CONTROL , headerValue );
561
- }
562
-
563
- if (response .containsHeader (HEADER_PRAGMA )) {
564
- // Reset HTTP 1.0 Pragma header if present
565
- response .setHeader (HEADER_PRAGMA , "" );
566
- }
567
- }
568
-
569
- /**
570
- * Prevent the response from being cached.
571
- * Only called in HTTP 1.0 compatibility mode.
572
- * <p>See {@code https://www.mnot.net/cache_docs}.
573
- * @deprecated as of 4.2, in favor of {@link #applyCacheControl}
574
- */
575
- @ Deprecated
576
- protected final void preventCaching (HttpServletResponse response ) {
577
- response .setHeader (HEADER_PRAGMA , "no-cache" );
578
-
579
- if (this .useExpiresHeader ) {
580
- // HTTP 1.0 Expires header
581
- response .setDateHeader (HEADER_EXPIRES , 1L );
582
- }
583
-
584
- if (this .useCacheControlHeader ) {
585
- // HTTP 1.1 Cache-Control header: "no-cache" is the standard value,
586
- // "no-store" is necessary to prevent caching on Firefox.
587
- response .setHeader (HEADER_CACHE_CONTROL , "no-cache" );
588
- if (this .useCacheControlNoStore ) {
589
- response .addHeader (HEADER_CACHE_CONTROL , "no-store" );
590
- }
591
- }
592
- }
593
-
594
-
595
363
private Collection <String > getVaryRequestHeadersToAdd (HttpServletResponse response , String [] varyByRequestHeaders ) {
596
364
if (!response .containsHeader (HttpHeaders .VARY )) {
597
365
return Arrays .asList (varyByRequestHeaders );
0 commit comments