aboutsummaryrefslogtreecommitdiff
path: root/challange_http.go
diff options
context:
space:
mode:
authorDimitri Sokolyuk <demon@dim13.org>2015-12-23 14:44:22 +0100
committerDimitri Sokolyuk <demon@dim13.org>2015-12-23 14:44:22 +0100
commit5fd587332fcc304fa21da782c62409b860f269e6 (patch)
tree7ec7e433bb73de4d3af49336ae692ede7e554806 /challange_http.go
parent21376df84168ce1adc74221fd0ab39fca28b70be (diff)
One shot http server
Diffstat (limited to 'challange_http.go')
-rw-r--r--challange_http.go36
1 files changed, 36 insertions, 0 deletions
diff --git a/challange_http.go b/challange_http.go
index 2d10da4..30233bb 100644
--- a/challange_http.go
+++ b/challange_http.go
@@ -1,7 +1,43 @@
package acme
+import (
+ "io"
+ "net"
+ "net/http"
+)
+
const wellKnown = `/.well-known/acme-challenge/`
func init() {
registerChallenge(ChallengeHTTP)
}
+
+type httpChallenge struct {
+ Challenge
+ Addr string
+}
+
+func (c *httpChallenge) ServeHTTP(w http.ResponseWriter, r *http.Request) {
+ io.WriteString(w, c.KeyAuthorization)
+}
+
+func (c *httpChallenge) Solve() error {
+ done := make(chan bool)
+ l, err := net.Listen("tcp", c.Addr)
+ if err != nil {
+ return err
+ }
+ defer l.Close()
+ s := &http.Server{
+ Handler: c,
+ ConnState: func(_ net.Conn, st http.ConnState) {
+ if st == http.StateClosed {
+ done <- true
+ }
+ },
+ }
+ s.SetKeepAlivesEnabled(false)
+ go s.Serve(l)
+ <-done
+ return nil
+}