Skip to content

Commit 81de9c4

Browse files
committed
Don't store responses from uncacheable methods.
Inline two parseCacheControl calls so they can be skipped if unnecessary due to cacheableMethod being false. Fixes #50.
1 parent ed02b2f commit 81de9c4

File tree

1 file changed

+1
-4
lines changed

1 file changed

+1
-4
lines changed

‎httpcache.go‎

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -281,10 +281,7 @@ func (t *Transport) RoundTrip(req *http.Request) (resp *http.Response, err error
281281
}
282282
}
283283

284-
reqCacheControl := parseCacheControl(req.Header)
285-
respCacheControl := parseCacheControl(resp.Header)
286-
287-
if canStore(reqCacheControl, respCacheControl) {
284+
if cacheableMethod && canStore(parseCacheControl(req.Header), parseCacheControl(resp.Header)) {
288285
for _, varyKey := range headerAllCommaSepValues(resp.Header, "vary") {
289286
varyKey = http.CanonicalHeaderKey(varyKey)
290287
fakeHeader := "X-Varied-" + varyKey

0 commit comments

Comments
 (0)