Disable keepalive to keep server from serving stale results.

Fixes issue #402

Bonus fix: Fix "multiple header writes" warning when no code is received.
This commit is contained in:
Klaus Post 2016-03-23 14:00:43 +01:00 committed by Nick Craig-Wood
parent 8f4d6973fb
commit f8101771c9

View file

@ -319,15 +319,17 @@ func (s *authServer) Start() {
Addr: s.bindAddress, Addr: s.bindAddress,
Handler: mux, Handler: mux,
} }
server.SetKeepAlivesEnabled(false)
mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, req *http.Request) { mux.HandleFunc("/favicon.ico", func(w http.ResponseWriter, req *http.Request) {
http.Error(w, "", 404) http.Error(w, "", 404)
return return
}) })
mux.HandleFunc("/auth", func(w http.ResponseWriter, req *http.Request) { 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 return
}) })
mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) { mux.HandleFunc("/", func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Content-Type", "text/html")
fs.Debug(nil, "Received request on auth server") fs.Debug(nil, "Received request on auth server")
code := req.FormValue("code") code := req.FormValue("code")
if code != "" { if code != "" {
@ -347,8 +349,9 @@ func (s *authServer) Start() {
return return
} }
fs.Debug(nil, "No code found on request") fs.Debug(nil, "No code found on request")
fmt.Fprintf(w, "<h1>Failed!</h1>\nNo code found.") w.WriteHeader(500)
http.Error(w, "", 500) fmt.Fprintf(w, "<h1>Failed!</h1>\nNo code found returned by remote server.")
}) })
var err error var err error