aboutsummaryrefslogtreecommitdiff
path: root/challange_http.go
diff options
context:
space:
mode:
Diffstat (limited to 'challange_http.go')
-rw-r--r--challange_http.go16
1 files changed, 7 insertions, 9 deletions
diff --git a/challange_http.go b/challange_http.go
index 7b2de54..bcc4691 100644
--- a/challange_http.go
+++ b/challange_http.go
@@ -7,7 +7,6 @@ import (
"net/http"
"os"
"path"
- "sync"
)
const wellKnown = `/.well-known/acme-challenge/`
@@ -19,30 +18,29 @@ func init() {
type httpChallenge struct {
Challenge
Addr string
- wg sync.WaitGroup
+ l net.Listener
}
func (c *httpChallenge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
if r.URL.Path == path.Join(wellKnown, c.Token) {
io.WriteString(w, c.KeyAuthorization)
- c.wg.Done()
+ c.l.Close()
}
}
func (c *httpChallenge) Solve() error {
- l, err := net.Listen("tcp", c.Addr)
+ var err error
+ c.l, err = net.Listen("tcp", c.Addr)
if err != nil {
return err
}
- defer l.Close()
- c.wg.Add(1)
- go http.Serve(l, c)
- c.wg.Wait()
+ defer c.l.Close()
+ http.Serve(c.l, c)
return nil
}
func (c *httpChallenge) Abort() error {
- c.wg.Done()
+ c.l.Close()
return nil
}