Join paths correcty in socketio.redirect

pull/12/head
Martin Boehm 2018-06-18 18:21:18 +02:00
parent 1a595362dd
commit 6078744489
1 changed files with 13 additions and 2 deletions

View File

@ -128,16 +128,27 @@ func (s *SocketIoServer) Shutdown(ctx context.Context) error {
return s.https.Shutdown(ctx)
}
func joinURL(base string, part string) string {
if len(base) > 0 {
if len(base) > 0 && base[len(base)-1] == '/' && len(part) > 0 && part[0] == '/' {
return base + part[1:]
} else {
return base + part
}
}
return part
}
func (s *SocketIoServer) txRedirect(w http.ResponseWriter, r *http.Request) {
if s.explorerURL != "" {
http.Redirect(w, r, s.explorerURL+r.URL.Path, 302)
http.Redirect(w, r, joinURL(s.explorerURL, r.URL.Path), 302)
s.metrics.ExplorerViews.With(common.Labels{"action": "tx"}).Inc()
}
}
func (s *SocketIoServer) addressRedirect(w http.ResponseWriter, r *http.Request) {
if s.explorerURL != "" {
http.Redirect(w, r, s.explorerURL+r.URL.Path, 302)
http.Redirect(w, r, joinURL(s.explorerURL, r.URL.Path), 302)
s.metrics.ExplorerViews.With(common.Labels{"action": "address"}).Inc()
}
}