@@ -178,6 +178,8 @@ func cacheSize() int {
178178func resetTest () {
179179 s .transport .Cache = newMemoryCache ()
180180 s .transport .CacheKey = nil
181+ s .transport .AlwaysUseCachedResponse = nil
182+ s .transport .ShouldCache = nil
181183 s .transport .EnableETagPair = false
182184 s .transport .MarkCachedResponses = false
183185 clock = & realClock {}
@@ -269,6 +271,30 @@ func TestAlwaysUseCachedResponse(t *testing.T) {
269271 }
270272}
271273
274+ func TestShouldCache (t * testing.T ) {
275+ resetTest ()
276+ c := qt .New (t )
277+ s .transport .AlwaysUseCachedResponse = func (req * http.Request , key string ) bool {
278+ return true
279+ }
280+
281+ s .transport .ShouldCache = func (req * http.Request , resp * http.Response , key string ) bool {
282+ return req .Header .Get ("Hello" ) == "world2"
283+ }
284+ {
285+ s , _ := doMethod (t , "GET" , "/helloheaderasbody" , map [string ]string {"Hello" : "world1" })
286+ c .Assert (s , qt .Equals , "world1" )
287+ }
288+ {
289+ s , _ := doMethod (t , "GET" , "/helloheaderasbody" , map [string ]string {"Hello" : "world2" })
290+ c .Assert (s , qt .Equals , "world2" )
291+ }
292+ {
293+ s , _ := doMethod (t , "GET" , "/helloheaderasbody" , map [string ]string {"Hello" : "world3" })
294+ c .Assert (s , qt .Equals , "world2" )
295+ }
296+ }
297+
272298func TestAround (t * testing.T ) {
273299 resetTest ()
274300 c := qt .New (t )
0 commit comments