aboutsummaryrefslogtreecommitdiff
path: root/go/weed
diff options
context:
space:
mode:
authorChris Lu <chris.lu@gmail.com>2013-07-08 23:38:38 -0700
committerChris Lu <chris.lu@gmail.com>2013-07-08 23:38:38 -0700
commitcbd9d14cc4dd6595617226cc68dcbf6513384541 (patch)
tree444981f4eeed15560effe86393c937f6d424430a /go/weed
parent53ae13a01257c3f6d21e3415fd03b2d55de91ef9 (diff)
downloadseaweedfs-cbd9d14cc4dd6595617226cc68dcbf6513384541.tar.xz
seaweedfs-cbd9d14cc4dd6595617226cc68dcbf6513384541.zip
Issue 27: feature request - Last-Modified header
Diffstat (limited to 'go/weed')
-rw-r--r--go/weed/volume.go15
-rw-r--r--go/weed/volume_test.go11
2 files changed, 22 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") {
diff --git a/go/weed/volume_test.go b/go/weed/volume_test.go
new file mode 100644
index 000000000..09340910b
--- /dev/null
+++ b/go/weed/volume_test.go
@@ -0,0 +1,11 @@
+package main
+
+import (
+ "net/http"
+ "testing"
+ "time"
+)
+
+func TestXYZ(t *testing.T) {
+ println("Last-Modified", time.Unix(int64(1373273596), 0).UTC().Format(http.TimeFormat))
+}