Skip to content

Commit 0e0bfdd

Browse files
committed
Cache key with Method and URL
1 parent 553cabb commit 0e0bfdd

File tree

2 files changed

+16
-1
lines changed

2 files changed

+16
-1
lines changed

‎httpcache.go‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ type Cache interface {
3939

4040
// cacheKey returns the cache key for req.
4141
func cacheKey(req *http.Request) string {
42-
return req.URL.String()
42+
return fmt.Sprintf("%s_%s", req.Method, req.URL.String())
4343
}
4444

4545
// CachedResponse returns the cached http.Response for req if present, and nil

‎httpcache_test.go‎

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -401,3 +401,18 @@ func (s *S) TestMaxStaleValue(c *C) {
401401

402402
c.Assert(getFreshness(respHeaders, reqHeaders), Equals, stale)
403403
}
404+
405+
func (s *S) TestGetAndHeadSameUrl(c *C) {
406+
req, err := http.NewRequest("HEAD", s.server.URL+"/", nil)
407+
req.Header.Set("Accept", "text/plain")
408+
resp, err := s.client.Do(req)
409+
defer resp.Body.Close()
410+
c.Assert(err, IsNil)
411+
c.Assert(resp.Header.Get(XFromCache), Equals, "")
412+
413+
req2, err := http.NewRequest("GET", s.server.URL+"/", nil)
414+
resp2, err2 := s.client.Do(req2)
415+
defer resp2.Body.Close()
416+
c.Assert(err2, IsNil)
417+
c.Assert(resp2.Header.Get(XFromCache), Equals, "")
418+
}

0 commit comments

Comments
 (0)