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