From b8a240fdf4f0496271ad7d2b04bc663473ff889d Mon Sep 17 00:00:00 2001 From: Thibaut Horel Date: Sun, 30 Dec 2018 06:48:35 -0500 Subject: Remove hard-coding of X-Remote-User --- main.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'main.go') diff --git a/main.go b/main.go index 174a610..34667cf 100644 --- a/main.go +++ b/main.go @@ -17,6 +17,7 @@ type App struct { Store Template *template.Template Domain string + Header string } func logMux(handler http.Handler) http.Handler { @@ -40,7 +41,7 @@ func (app *App) validate(r *http.Request) (*Session, bool) { func (app *App) validateHandler(w http.ResponseWriter, r *http.Request) { if s, ok := app.validate(r); ok { - w.Header().Set("X-Remote-User", strconv.FormatInt(s.UserId, 10)) + w.Header().Set(app.Header, strconv.FormatInt(s.UserId, 10)) w.WriteHeader(http.StatusOK) } else { w.WriteHeader(http.StatusUnauthorized) @@ -112,6 +113,11 @@ func main() { } address := flag.String("a", ":8080", "bind the server to `address`") templateDir := flag.String("t", "templates", "template `directory`") + header := flag.String( + "header", + "X-Remote-User", + "http `header` containing the user id", + ) flag.Parse() if flag.NArg() < 2 { fmt.Print("Argument missing. ") @@ -123,7 +129,7 @@ func main() { template := template.Must( template.New("").ParseGlob(filepath.Join(*templateDir, "*.tmpl")), ) - app := &App{store, template, flag.Args()[1]} + app := &App{store, template, flag.Args()[1], *header} http.HandleFunc("/validate", app.validateHandler) http.HandleFunc("/login", app.loginHandler) http.HandleFunc("/logout", app.logoutHandler) -- cgit v1.2.3-70-g09d2