From f8101771c96047442f8f9a7c38c5eb9ec0f1648d Mon Sep 17 00:00:00 2001 From: Klaus Post Date: Wed, 23 Mar 2016 14:00:43 +0100 Subject: [PATCH] Disable keepalive to keep server from serving stale results. Fixes issue #402 Bonus fix: Fix "multiple header writes" warning when no code is received. --- oauthutil/oauthutil.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/oauthutil/oauthutil.go b/oauthutil/oauthutil.go index 3962af81b..c16d94277 100644 --- a/oauthutil/oauthutil.go +++ b/oauthutil/oauthutil.go @@ -319,15 +319,17 @@ func (s *authServer) Start() { Addr: s.bindAddress, Handler: mux, } + server.SetKeepAlivesEnabled(false) mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, req *http.Request) { http.Error(w, "", 404) return }) mux.HandleFunc("/auth", func(w http.ResponseWriter, req *http.Request) { - http.Redirect(w, req, s.authURL, 307) + http.Redirect(w, req, s.authURL, http.StatusTemporaryRedirect) return }) mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { + w.Header().Set("Content-Type", "text/html") fs.Debug(nil, "Received request on auth server") code := req.FormValue("code") if code != "" { @@ -347,8 +349,9 @@ func (s *authServer) Start() { return } fs.Debug(nil, "No code found on request") - fmt.Fprintf(w, "

Failed!

\nNo code found.") - http.Error(w, "", 500) + w.WriteHeader(500) + fmt.Fprintf(w, "

Failed!

\nNo code found returned by remote server.") + }) var err error