From 9b40934654d80cf35967f1265f155f6217d370be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ken-H=C3=A5vard=20Lieng?= Date: Thu, 22 Nov 2018 10:40:29 +0100 Subject: [PATCH] Grab referer in /init handler instead of getIndexData() --- server/index_data.go | 9 --------- server/server.go | 9 ++++++++- 2 files changed, 8 insertions(+), 10 deletions(-) diff --git a/server/index_data.go b/server/index_data.go index 7f588041..926c0213 100644 --- a/server/index_data.go +++ b/server/index_data.go @@ -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) diff --git a/server/server.go b/server/server.go index c8c8a842..779b88bc 100644 --- a/server/server.go +++ b/server/server.go @@ -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) }