Skip to content

Commit

Permalink
Add Etag support
Browse files Browse the repository at this point in the history
  • Loading branch information
chrislusf committed Jul 22, 2014
1 parent 5d88cec commit 530927d
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 0 deletions.
8 changes: 8 additions & 0 deletions go/storage/crc.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package storage

import (
"code.google.com/p/weed-fs/go/util"
"fmt"
"hash/crc32"
)

Expand All @@ -19,3 +21,9 @@ func (c CRC) Update(b []byte) CRC {
func (c CRC) Value() uint32 {
return uint32(c>>15|c<<17) + 0xa282ead8
}

func (n *Needle) Etag() string {
bits := make([]byte, 4)
util.Uint32toBytes(bits, uint32(n.Checksum))
return fmt.Sprintf("%x", bits)
}
6 changes: 6 additions & 0 deletions go/weed/weed_server/volume_server_handlers.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ func (vs *VolumeServer) GetOrHeadHandler(w http.ResponseWriter, r *http.Request)
}
}
}
etag := n.Etag()
if inm := r.Header.Get("If-None-Match"); inm == etag {
w.WriteHeader(http.StatusNotModified)
return
}
w.Header().Set("Etag", etag)
if n.NameSize > 0 && filename == "" {
filename = string(n.Name)
dotIndex := strings.LastIndex(filename, ".")
Expand Down

0 comments on commit 530927d

Please sign in to comment.