// The name is otherwise unused; in particular it can be empty and is
// never sent in the response.
//
-// If modtime is not the zero time, ServeContent includes it in a
-// Last-Modified header in the response. If the request includes an
-// If-Modified-Since header, ServeContent uses modtime to decide
-// whether the content needs to be sent at all.
+// If modtime is not the zero time or Unix epoch, ServeContent
+// includes it in a Last-Modified header in the response. If the
+// request includes an If-Modified-Since header, ServeContent uses
+// modtime to decide whether the content needs to be sent at all.
//
// The content's Seek method must work: ServeContent uses
// a seek to the end of the content to determine its size.
}
}
+var unixEpochTime = time.Unix(0, 0)
+
// modtime is the modification time of the resource to be served, or IsZero().
// return value is whether this request is now complete.
func checkLastModified(w ResponseWriter, r *Request, modtime time.Time) bool {
- if modtime.IsZero() {
+ if modtime.IsZero() || modtime.Equal(unixEpochTime) {
+ // If the file doesn't have a modtime (IsZero), or the modtime
+ // is obviously garbage (Unix time == 0), then ignore modtimes
+ // and don't process the If-Modified-Since header.
return false
}
wantContentType: "text/css; charset=utf-8",
wantLastMod: "Wed, 25 Jun 2014 17:12:18 GMT",
},
+ "unix_zero_modtime": {
+ content: strings.NewReader("<html>foo"),
+ modtime: time.Unix(0, 0),
+ wantStatus: StatusOK,
+ wantContentType: "text/html; charset=utf-8",
+ },
}
for testName, tt := range tests {
var content io.ReadSeeker