Skip to content

SeaweedFS is a distributed storage system for object storage (S3), file systems, Iceberg table buckets, and Lance vector buckets, designed to handle billions of files with O(1) disk access and effortless horizontal scaling.

301 is reported as 404 for http post

Chris Lu72e89b615b02
diff --git a/weed/server/raft_server.go b/weed/server/raft_server.go
index 35b8027539..e3914d9f89 100644
--- a/weed/server/raft_server.go
+++ b/weed/server/raft_server.go
@@ -189,14 +189,12 @@ func postFollowingOneRedirect(target string, contentType string, b bytes.Buffer)
return err
}
defer resp.Body.Close()
- reply, _ := ioutil.ReadAll(resp.Body)
statusCode := resp.StatusCode
+ data, _ := ioutil.ReadAll(resp.Body)
+ reply := string(data)
- if statusCode == http.StatusMovedPermanently {
- var urlStr string
- if urlStr = resp.Header.Get("Location"); urlStr == "" {
- return fmt.Errorf("%d response missing Location header", resp.StatusCode)
- }
+ if strings.HasPrefix(reply, "\"http") {
+ urlStr := reply[1 : len(reply)-1]
glog.V(0).Infoln("Post redirected to ", urlStr)
resp2, err2 := http.Post(urlStr, contentType, backupReader)
@@ -204,13 +202,13 @@ func postFollowingOneRedirect(target string, contentType string, b bytes.Buffer)
return err2
}
defer resp2.Body.Close()
- reply, _ = ioutil.ReadAll(resp2.Body)
+ data, _ = ioutil.ReadAll(resp2.Body)
statusCode = resp2.StatusCode
}
- glog.V(0).Infoln("Post returned status: ", statusCode, string(reply))
+ glog.V(0).Infoln("Post returned status: ", statusCode, string(data))
if statusCode != http.StatusOK {
- return errors.New(string(reply))
+ return errors.New(string(data))
}
return nil
diff --git a/weed/server/raft_server_handlers.go b/weed/server/raft_server_handlers.go
index 335ba668fd..0a794ce6c9 100644
--- a/weed/server/raft_server_handlers.go
+++ b/weed/server/raft_server_handlers.go
@@ -44,8 +44,10 @@ func (s *RaftServer) HandleFunc(pattern string, handler func(http.ResponseWriter
func (s *RaftServer) redirectToLeader(w http.ResponseWriter, req *http.Request) {
if leader, e := s.topo.Leader(); e == nil {
//http.StatusMovedPermanently does not cause http POST following redirection
- glog.V(0).Infoln("Redirecting to", http.StatusMovedPermanently, "http://"+leader+req.URL.Path)
- http.Redirect(w, req, "http://"+leader+req.URL.Path, http.StatusMovedPermanently)
+ learderLocation := "http://" + leader + req.URL.Path
+ glog.V(0).Infoln("Redirecting to", learderLocation)
+ writeJsonQuiet(w, req, http.StatusOK, learderLocation)
+ // http.Redirect(w, req, "http://"+leader+req.URL.Path, http.StatusFound) // not working any more
} else {
glog.V(0).Infoln("Error: Leader Unknown")
http.Error(w, "Leader unknown", http.StatusInternalServerError)