@@ -10,11 +10,15 @@ import (
10
10
func TestCacheControl (t * testing.T ) {
11
11
w := httptest .NewRecorder ()
12
12
r , _ := http .NewRequest ("POST" , "http://example.com/foo" , nil )
13
- cached := Cached (http .HandlerFunc (func (w http.ResponseWriter , r * http.Request ) {}), MaxAge (time .Hour * 24 * 13 ), NoTransform ())
13
+ handler := func (w http.ResponseWriter , r * http.Request ) {}
14
+ opts := []optionFunc {MaxAge (time .Hour * 24 * 13 ), NoTransform ()}
15
+ cached := Cached (http .HandlerFunc (handler ), opts ... )
16
+
14
17
cached .ServeHTTP (w , r )
15
18
16
- if "no-transform, max-age=1123200" != w .Header ().Get ("Cache-Control" ) {
17
- t .Fatalf ("Cache-Control header: got %s, wanted 'no-transform, max-age=1123200'" , w .Header ().Get ("Cache-Control" ))
19
+ wanted := "no-transform, max-age=1123200"
20
+ if pragmas := w .Header ().Get ("Cache-Control" ); pragmas != wanted {
21
+ t .Fatalf ("Cache-Control header: got %s, wanted '%s'" , pragmas , wanted )
18
22
}
19
23
}
20
24
@@ -53,6 +57,7 @@ var cacheOptionFuncTests = []struct {
53
57
{MustRevalidate (), "must-revalidate" },
54
58
{ProxyRevalidate (), "proxy-revalidate" },
55
59
{SharedMaxAge (time .Hour * 13 ), "s-maxage=46800" },
60
+ {Config (CacheOptions {MaxAge : time .Hour * 24 * 13 , NoTransform : true }), "no-transform, max-age=1123200" },
56
61
}
57
62
58
63
func TestOptionFuncs (t * testing.T ) {
@@ -64,3 +69,18 @@ func TestOptionFuncs(t *testing.T) {
64
69
}
65
70
}
66
71
}
72
+
73
+ func TestMaintainsExistingCacheOptions (t * testing.T ) {
74
+ w := httptest .NewRecorder ()
75
+ r , _ := http .NewRequest ("POST" , "http://example.com/foo" , nil )
76
+ handler := func (w http.ResponseWriter , r * http.Request ) { w .Header ().Set ("Cache-Control" , "must-revalidate" ) }
77
+ opts := []optionFunc {MaxAge (time .Hour * 24 * 13 ), NoTransform ()}
78
+ cached := Cached (http .HandlerFunc (handler ), opts ... )
79
+
80
+ cached .ServeHTTP (w , r )
81
+
82
+ wanted := "must-revalidate"
83
+ if pragmas := w .Header ().Get ("Cache-Control" ); pragmas != wanted {
84
+ t .Fatalf ("Cache-Control header: got %s, wanted '%s'" , pragmas , wanted )
85
+ }
86
+ }
0 commit comments