Issue 27: feature request - Last-Modified header

This commit is contained in:
Chris Lu
2013-07-08 23:38:38 -07:00
parent 53ae13a012
commit cbd9d14cc4
4 changed files with 58 additions and 14 deletions

View File

@@ -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") {

11
go/weed/volume_test.go Normal file
View File

@@ -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))
}