Grab referer in /init handler instead of getIndexData()

This commit is contained in:
Ken-Håvard Lieng 2018-11-22 10:40:29 +01:00
parent bd0541120f
commit 9b40934654
2 changed files with 8 additions and 10 deletions

View File

@ -83,15 +83,6 @@ func getIndexData(r *http.Request, path string, state *State) *indexData {
}
data.Channels = channels
referer, err := url.Parse(r.Header.Get("Referer"))
if err == nil {
server, channel := getTabFromPath(referer.EscapedPath())
if isInChannel(channels, server, channel) {
data.addUsersAndMessages(server, channel, state)
return &data
}
}
server, channel := getTabFromPath(path)
if isInChannel(channels, server, channel) {
data.addUsersAndMessages(server, channel, state)

View File

@ -181,10 +181,17 @@ func (d *Dispatch) ServeHTTP(w http.ResponseWriter, r *http.Request) {
d.upgradeWS(w, r, state)
} else if strings.HasPrefix(r.URL.Path, "/init") {
referer, err := url.Parse(r.Header.Get("Referer"))
if err != nil {
fail(w, http.StatusInternalServerError)
return
}
state := d.handleAuth(w, r, true, true)
data := getIndexData(r, "/", state)
data := getIndexData(r, referer.EscapedPath(), state)
writeJSON(w, r, data)
} else {
d.serveFiles(w, r)
}