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)
| 490 | // req, based on the response resp. This is determined using the last modified |
| 491 | // time and the entity tag of resp. |
| 492 | func 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 | |
| 516 | func (p *Proxy) log(v ...any) { |
| 517 | if p.Logger != nil { |