Browse Source

Use request host info for master url if possible

Fix https://github.com/chrislusf/seaweedfs/issues/148
pull/174/head
chrislusf 10 years ago
parent
commit
3b2645979d
  1. 10
      go/weed/weed_server/master_server_handlers_admin.go

10
go/weed/weed_server/master_server_handlers_admin.go

@ -129,9 +129,15 @@ func (ms *MasterServer) redirectHandler(w http.ResponseWriter, r *http.Request)
}
}
func (ms *MasterServer) selfUrl(r *http.Request) string {
if r.Host != "" {
return r.Host
}
return "localhost:" + strconv.Itoa(ms.port)
}
func (ms *MasterServer) submitFromMasterServerHandler(w http.ResponseWriter, r *http.Request) {
if ms.Topo.IsLeader() {
submitForClientHandler(w, r, "localhost:"+strconv.Itoa(ms.port))
submitForClientHandler(w, r, ms.selfUrl(r))
} else {
masterUrl, err := ms.Topo.Leader()
if err != nil {
@ -144,7 +150,7 @@ func (ms *MasterServer) submitFromMasterServerHandler(w http.ResponseWriter, r *
func (ms *MasterServer) deleteFromMasterServerHandler(w http.ResponseWriter, r *http.Request) {
if ms.Topo.IsLeader() {
deleteForClientHandler(w, r, "localhost:"+strconv.Itoa(ms.port))
deleteForClientHandler(w, r, ms.selfUrl(r))
} else {
deleteForClientHandler(w, r, ms.Topo.RaftServer.Leader())
}

Loading…
Cancel
Save