modtime is the modification time of the resource to be served, or IsZero(). return value is whether this request is now complete.
(w http.ResponseWriter, r *http.Request, modtime time.Time)
| 161 | // modtime is the modification time of the resource to be served, or IsZero(). |
| 162 | // return value is whether this request is now complete. |
| 163 | func checkLastModified(w http.ResponseWriter, r *http.Request, modtime time.Time) bool { |
| 164 | if modtime.IsZero() { |
| 165 | return false |
| 166 | } |
| 167 | |
| 168 | // The Date-Modified header truncates sub-second precision, so |
| 169 | // use mtime < t+1s instead of mtime <= t to check for unmodified. |
| 170 | if t, err := time.Parse(http.TimeFormat, r.Header.Get("If-Modified-Since")); err == nil && modtime.Before(t.Add(1*time.Second)) { |
| 171 | h := w.Header() |
| 172 | delete(h, "Content-Type") |
| 173 | delete(h, "Content-Length") |
| 174 | w.WriteHeader(http.StatusNotModified) |
| 175 | return true |
| 176 | } |
| 177 | w.Header().Set("Last-Modified", modtime.UTC().Format(http.TimeFormat)) |
| 178 | return false |
| 179 | } |
| 180 | |
| 181 | // checkETag implements If-None-Match checks. |
| 182 | // The ETag must have been previously set in the ResponseWriter's headers. |
no test coverage detected