MCPcopy
hub / github.com/willnorris/imageproxy / should304

Function should304

imageproxy.go:492–514  ·  view source on GitHub ↗

should304 returns whether we should send a 304 Not Modified in response to req, based on the response resp. This is determined using the last modified time and the entity tag of resp.

(req *http.Request, resp *http.Response)

Source from the content-addressed store, hash-verified

490// req, based on the response resp. This is determined using the last modified
491// time and the entity tag of resp.
492func should304(req *http.Request, resp *http.Response) bool {
493 // TODO(willnorris): if-none-match header can be a comma separated list
494 // of multiple tags to be matched, or the special value "*" which
495 // matches all etags
496 etag := resp.Header.Get("Etag")
497 if etag != "" && etag == req.Header.Get("If-None-Match") {
498 return true
499 }
500
501 lastModified, err := time.Parse(time.RFC1123, resp.Header.Get("Last-Modified"))
502 if err != nil {
503 return false
504 }
505 ifModSince, err := time.Parse(time.RFC1123, req.Header.Get("If-Modified-Since"))
506 if err != nil {
507 return false
508 }
509 if lastModified.Before(ifModSince) || lastModified.Equal(ifModSince) {
510 return true
511 }
512
513 return false
514}
515
516func (p *Proxy) log(v ...any) {
517 if p.Logger != nil {

Callers 3

TestShould304Function · 0.85
serveImageMethod · 0.85
RoundTripMethod · 0.85

Calls 1

GetMethod · 0.65

Tested by 1

TestShould304Function · 0.68