diff options
| author | Chris Lu <chris.lu@gmail.com> | 2012-09-20 02:47:32 -0700 |
|---|---|---|
| committer | Chris Lu <chris.lu@gmail.com> | 2012-09-20 02:47:32 -0700 |
| commit | 462f2ed9589425610789ffe597defae8041e9782 (patch) | |
| tree | e3497cdacb068c0da6c44ae5418988702afd9502 /weed-fs/src/cmd | |
| parent | a1bc529db65aa67ff7d52b76d700c093eb0c6c17 (diff) | |
| download | seaweedfs-462f2ed9589425610789ffe597defae8041e9782.tar.xz seaweedfs-462f2ed9589425610789ffe597defae8041e9782.zip | |
for moved volumes, redirect with code 501
Diffstat (limited to 'weed-fs/src/cmd')
| -rw-r--r-- | weed-fs/src/cmd/weed/master.go | 2 | ||||
| -rw-r--r-- | weed-fs/src/cmd/weed/volume.go | 19 |
2 files changed, 17 insertions, 4 deletions
diff --git a/weed-fs/src/cmd/weed/master.go b/weed-fs/src/cmd/weed/master.go index d2e58eb5b..bd2323d2a 100644 --- a/weed-fs/src/cmd/weed/master.go +++ b/weed-fs/src/cmd/weed/master.go @@ -53,7 +53,7 @@ func dirLookupHandler(w http.ResponseWriter, r *http.Request) { for _, machine := range machines { ret = append(ret, map[string]string{"url": machine.Url, "publicUrl": machine.PublicUrl}) } - writeJson(w, r, ret) + writeJson(w, r, map[string]interface{}{"locations":ret}) } else { log.Println("Invalid volume id", volumeId) writeJson(w, r, map[string]string{"error": "volume id " + volumeId.String() + " not found. " + e.Error()}) diff --git a/weed-fs/src/cmd/weed/volume.go b/weed-fs/src/cmd/weed/volume.go index 66296c5ee..3b41a60d1 100644 --- a/weed-fs/src/cmd/weed/volume.go +++ b/weed-fs/src/cmd/weed/volume.go @@ -7,6 +7,7 @@ import ( "mime" "net/http" "os" + "pkg/operation" "pkg/storage" "strconv" "strings" @@ -86,11 +87,23 @@ func GetHandler(w http.ResponseWriter, r *http.Request) { if *IsDebug { log.Println("volume", volumeId, "reading", n) } + if !store.HasVolume(volumeId) { + lookupResult, err := operation.Lookup(*server, volumeId) + if *IsDebug { + log.Println("volume", volumeId, "found on", lookupResult, "error", err) + } + if err == nil { + http.Redirect(w, r, "http://"+lookupResult.Locations[0].PublicUrl+r.URL.Path, http.StatusMovedPermanently) + } else { + w.WriteHeader(http.StatusNotFound) + } + return + } cookie := n.Cookie count, e := store.Read(volumeId, n) - if *IsDebug { - log.Println("read bytes", count, "error", e) - } + if *IsDebug { + log.Println("read bytes", count, "error", e) + } if e != nil || count <= 0 { w.WriteHeader(404) return |
