File tree Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Expand file tree Collapse file tree 1 file changed +9
-7
lines changed Original file line number Diff line number Diff line change @@ -340,15 +340,17 @@ func cacheControl(alwaysValidate bool) ClientMiddleware {
340
340
if ! alwaysValidate {
341
341
return next
342
342
}
343
+
344
+ // Force validation to occur when the cache is disabled by setting
345
+ // max-age=0 so that cached results will always appear to be stale
343
346
return roundTripperFunc (func (r * http.Request ) (* http.Response , error ) {
344
347
resp , err := next .RoundTrip (r )
345
-
346
- // Force validation to occur when the cache is disabled by setting max-age=0,
347
- // as the cache results will always appear as stale
348
- cacheControl := resp .Header .Get ("Cache-Control" )
349
- if cacheControl != "" {
350
- newCacheControl := maxAgeRegex .ReplaceAllString (cacheControl , "max-age=0" )
351
- resp .Header .Set ("Cache-Control" , newCacheControl )
348
+ if resp != nil {
349
+ cacheControl := resp .Header .Get ("Cache-Control" )
350
+ if cacheControl != "" {
351
+ newCacheControl := maxAgeRegex .ReplaceAllString (cacheControl , "max-age=0" )
352
+ resp .Header .Set ("Cache-Control" , newCacheControl )
353
+ }
352
354
}
353
355
return resp , err
354
356
})
You can’t perform that action at this time.
0 commit comments