Add hooks to SimpleHTTP

This commit is contained in:
xenolf 2015-11-03 00:02:47 +01:00
parent a2867a0c18
commit 3e1a5dc04b

View file

@ -14,6 +14,12 @@ import (
"time" "time"
) )
// OnSimpleHTTPStart hook will get called BEFORE SimpleHTTP starts to listen on a port.
var OnSimpleHTTPStart func(string)
// OnSimpleHTTPEnd hook will get called AFTER SimpleHTTP determined the status of the domain.
var OnSimpleHTTPEnd func(bool)
type simpleHTTPChallenge struct { type simpleHTTPChallenge struct {
jws *jws jws *jws
optPort string optPort string
@ -59,11 +65,17 @@ Loop:
switch challengeResponse.Status { switch challengeResponse.Status {
case "valid": case "valid":
if OnSimpleHTTPEnd != nil {
OnSimpleHTTPEnd(true)
}
logger().Print("The server validated our request") logger().Print("The server validated our request")
break Loop break Loop
case "pending": case "pending":
break break
case "invalid": case "invalid":
if OnSimpleHTTPEnd != nil {
OnSimpleHTTPEnd(true)
}
return errors.New("The server could not validate our request.") return errors.New("The server could not validate our request.")
default: default:
return errors.New("The server returned an unexpected state.") return errors.New("The server returned an unexpected state.")
@ -102,6 +114,9 @@ func (s *simpleHTTPChallenge) startHTTPSServer(domain string, token string) (net
tlsConf.Certificates = []tls.Certificate{tempKeyPair} tlsConf.Certificates = []tls.Certificate{tempKeyPair}
path := "/.well-known/acme-challenge/" + token path := "/.well-known/acme-challenge/" + token
if OnSimpleHTTPStart != nil {
OnSimpleHTTPStart(path)
}
// Allow for CLI override // Allow for CLI override
port := ":443" port := ":443"