MCPcopy
hub / github.com/cortesi/devd / checkLastModified

Function checkLastModified

fileserver/fileserver.go:163–179  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

161// modtime is the modification time of the resource to be served, or IsZero().
162// return value is whether this request is now complete.
163func 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.

Callers 2

serveContentFunction · 0.85
notFoundMethod · 0.85

Calls 3

AddMethod · 0.80
HeaderMethod · 0.80
WriteHeaderMethod · 0.80

Tested by

no test coverage detected