Use a local ServeMux in httpChallenge.Solve.

Avoids modifying global state.
This commit is contained in:
Tommie Gannert 2015-12-05 12:05:40 +00:00
parent 38cb60624f
commit bee1326835

View file

@ -42,7 +42,8 @@ func (s *httpChallenge) Solve(chlng challenge, domain string) error {
// The handler validates the HOST header and request type. // The handler validates the HOST header and request type.
// For validation it then writes the token the server returned with the challenge // 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" { if strings.HasPrefix(r.Host, domain) && r.Method == "GET" {
w.Header().Add("Content-Type", "text/plain") w.Header().Add("Content-Type", "text/plain")
w.Write([]byte(keyAuth)) 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}) return validate(s.jws, chlng.URI, challenge{Resource: "challenge", Type: chlng.Type, Token: chlng.Token, KeyAuthorization: keyAuth})
} }