From bee1326835c4aeeb210f85e778ebe0b1f8e745b9 Mon Sep 17 00:00:00 2001 From: Tommie Gannert Date: Sat, 5 Dec 2015 12:05:40 +0000 Subject: [PATCH] Use a local ServeMux in httpChallenge.Solve. Avoids modifying global state. --- acme/http_challenge.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/acme/http_challenge.go b/acme/http_challenge.go index 87359049..d313b1ab 100644 --- a/acme/http_challenge.go +++ b/acme/http_challenge.go @@ -42,7 +42,8 @@ func (s *httpChallenge) Solve(chlng challenge, domain string) error { // The handler validates the HOST header and request type. // For validation it then writes the token the server returned with the challenge - http.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { + mux := http.NewServeMux() + mux.HandleFunc(path, func(w http.ResponseWriter, r *http.Request) { if strings.HasPrefix(r.Host, domain) && r.Method == "GET" { w.Header().Add("Content-Type", "text/plain") w.Write([]byte(keyAuth)) @@ -53,7 +54,7 @@ func (s *httpChallenge) Solve(chlng challenge, domain string) error { } }) - go http.Serve(listener, nil) + go http.Serve(listener, mux) return validate(s.jws, chlng.URI, challenge{Resource: "challenge", Type: chlng.Type, Token: chlng.Token, KeyAuthorization: keyAuth}) }