Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add http-01 support to the Let's Encrypt mechanism. #8

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 7 additions & 5 deletions httputil/httputil.go
Original file line number Diff line number Diff line change
Expand Up @@ -267,18 +267,20 @@ func ListenAndServe(opts ...Option) error {
errs <- (&http.Server{
ReadTimeout: 5 * time.Second,
WriteTimeout: 5 * time.Second,
Handler: http.HandlerFunc(func(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Connection", "close")
url := "https://" + req.Host + req.URL.String()
http.Redirect(w, req, url, http.StatusMovedPermanently)
}),
Handler: m.HTTPHandler(http.HandlerFunc(redirect)),
Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I'll need to refactor this a little since currently this code will only run if redirectHTTPS is true and we might be using Let's Encrypt but not doing redirects in that case these changes wouldn't work.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Added a fixup in 178158e. If redirectHTTPS is true or we've set the GetCertificate config which indicates we're using Let's Encrypt then we will start the http listener. Using the redirect methods in both cases should be fine because the autocert.HTTPHandler will do a redirect anyway if nil is passed in which is the other option we could do. I think this should correctly work now in all cases

}).ListenAndServe()
}()
}

return <-errs
}

func redirect(w http.ResponseWriter, req *http.Request) {
w.Header().Set("Connection", "close")
url := "https://" + req.Host + req.URL.String()
http.Redirect(w, req, url, http.StatusMovedPermanently)
}

// tlsProfile represents a collection of TLS CipherSuites and their compatibility with Web Browsers.
// The different profile types are defined on the Mozilla wiki: https://wiki.mozilla.org/Security/Server_Side_TLS
type tlsProfile int
Expand Down