From ac74ee14688b9b5626c0099a3c4d3e03ca1c71e8 Mon Sep 17 00:00:00 2001 From: Jakob Borg Date: Wed, 30 Apr 2014 22:10:13 +0200 Subject: [PATCH] Don't redirect to absolute URL (fixes #166) --- cmd/syncthing/gui.go | 7 +++++-- cmd/syncthing/gui_embedded.go | 3 +-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/cmd/syncthing/gui.go b/cmd/syncthing/gui.go index 8033ff5c8..2b0b23849 100644 --- a/cmd/syncthing/gui.go +++ b/cmd/syncthing/gui.go @@ -25,6 +25,8 @@ var ( configInSync = true guiErrors = []guiError{} guiErrorsMut sync.Mutex + static = embeddedStatic() + staticFunc = static.(func(http.ResponseWriter, *http.Request)) ) const ( @@ -53,7 +55,7 @@ func startGUI(cfg GUIConfiguration, m *Model) { if len(cfg.User) > 0 && len(cfg.Password) > 0 { mr.Use(basic(cfg.User, cfg.Password)) } - mr.Use(embeddedStatic()) + mr.Use(static) mr.Use(martini.Recovery()) mr.Use(restMiddleware) mr.Action(router.Handle) @@ -66,7 +68,8 @@ func startGUI(cfg GUIConfiguration, m *Model) { } func getRoot(w http.ResponseWriter, r *http.Request) { - http.Redirect(w, r, "/index.html", 302) + r.URL.Path = "/index.html" + staticFunc(w, r) } func restMiddleware(w http.ResponseWriter, r *http.Request) { diff --git a/cmd/syncthing/gui_embedded.go b/cmd/syncthing/gui_embedded.go index 04cc5af8c..3bf656ec9 100644 --- a/cmd/syncthing/gui_embedded.go +++ b/cmd/syncthing/gui_embedded.go @@ -4,7 +4,6 @@ package main import ( "fmt" - "log" "mime" "net/http" "path/filepath" @@ -16,7 +15,7 @@ import ( func embeddedStatic() interface{} { var modt = time.Now().UTC().Format(http.TimeFormat) - return func(res http.ResponseWriter, req *http.Request, log *log.Logger) { + return func(res http.ResponseWriter, req *http.Request) { file := req.URL.Path if file[0] == '/' {