Browse Source

adding HEAD support

pull/2/head
Chris Lu 12 years ago
parent
commit
4d8ce2fe26
  1. 12
      go/weed/volume.go

12
go/weed/volume.go

@ -89,14 +89,16 @@ func vacuumVolumeCommitHandler(w http.ResponseWriter, r *http.Request) {
func storeHandler(w http.ResponseWriter, r *http.Request) { func storeHandler(w http.ResponseWriter, r *http.Request) {
switch r.Method { switch r.Method {
case "GET": case "GET":
GetHandler(w, r)
GetOrHeadHandler(w, r, true)
case "HEAD":
GetOrHeadHandler(w, r, false)
case "DELETE": case "DELETE":
DeleteHandler(w, r) DeleteHandler(w, r)
case "POST": case "POST":
PostHandler(w, r) PostHandler(w, r)
} }
} }
func GetHandler(w http.ResponseWriter, r *http.Request) {
func GetOrHeadHandler(w http.ResponseWriter, r *http.Request, isGetMethod bool) {
n := new(storage.Needle) n := new(storage.Needle)
vid, fid, ext := parseURLPath(r.URL.Path) vid, fid, ext := parseURLPath(r.URL.Path)
volumeId, err := storage.NewVolumeId(vid) volumeId, err := storage.NewVolumeId(vid)
@ -163,8 +165,10 @@ func GetHandler(w http.ResponseWriter, r *http.Request) {
} }
} }
w.Header().Set("Content-Length", strconv.Itoa(len(n.Data))) w.Header().Set("Content-Length", strconv.Itoa(len(n.Data)))
if _, e = w.Write(n.Data); e != nil {
debug("response write error:", e)
if isGetMethod {
if _, e = w.Write(n.Data); e != nil {
debug("response write error:", e)
}
} }
} }
func PostHandler(w http.ResponseWriter, r *http.Request) { func PostHandler(w http.ResponseWriter, r *http.Request) {

Loading…
Cancel
Save