mirror of
https://github.com/seaweedfs/seaweedfs.git
synced 2024-01-19 02:48:24 +00:00
301 is reported as 404 for http post
fix https://github.com/chrislusf/seaweedfs/issues/512
This commit is contained in:
parent
761c0eb1ed
commit
72e89b615b
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in a new issue