diff options
| author | Chris Lu <chris.lu@gmail.com> | 2013-07-08 23:38:38 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2013-07-08 23:38:38 -0700 |
| commit | cbd9d14cc4dd6595617226cc68dcbf6513384541 (patch) | |
| tree | 444981f4eeed15560effe86393c937f6d424430a /go/weed/volume.go | |
| parent | 53ae13a01257c3f6d21e3415fd03b2d55de91ef9 (diff) | |
| download | seaweedfs-cbd9d14cc4dd6595617226cc68dcbf6513384541.tar.xz seaweedfs-cbd9d14cc4dd6595617226cc68dcbf6513384541.zip | |
Issue 27: feature request - Last-Modified header
Diffstat (limited to 'go/weed/volume.go')
| -rw-r--r-- | go/weed/volume.go | 15 |
1 files changed, 11 insertions, 4 deletions
diff --git a/go/weed/volume.go b/go/weed/volume.go index 6282b0bc8..039212793 100644 --- a/go/weed/volume.go +++ b/go/weed/volume.go @@ -145,6 +145,17 @@ func GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) w.WriteHeader(http.StatusNotFound) return } + if n.LastModified != 0 { + w.Header().Set("Last-Modified", time.Unix(int64(n.LastModified), 0).UTC().Format(http.TimeFormat)) + if r.Header.Get("If-Modified-Since") != "" { + if t, parseError := time.Parse(http.TimeFormat, r.Header.Get("If-Modified-Since")); parseError == nil { + if t.Unix() <= int64(n.LastModified) { + w.WriteHeader(http.StatusNotModified) + return + } + } + } + } if n.NameSize > 0 { fname := string(n.Name) dotIndex := strings.LastIndex(fname, ".") @@ -165,10 +176,6 @@ func GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) if n.NameSize > 0 { w.Header().Set("Content-Disposition", "filename="+fileNameEscaper.Replace(string(n.Name))) } - if n.LastModified != 0 { - println("file time is", n.LastModified) - w.Header().Set("Last-Modified", time.Unix(int64(n.LastModified), 0).Format(http.TimeFormat)) - } if ext != ".gz" { if n.IsGzipped() { if strings.Contains(r.Header.Get("Accept-Encoding"), "gzip") { |
