Ensure certificate has a non-nil config when caching (fixes #875)

Also we change the scheme of the site's address if TLS is enabled and
no other scheme is explicitly set; this makes it appear as "https" when
we print it; otherwise it would show "http" when TLS is turned on
implicitly, and that is confusing/incorrect.
This commit is contained in:
Matthew Holt
2016-06-09 19:12:11 -06:00
parent 98cf26377c
commit daa4de572e
3 changed files with 15 additions and 2 deletions

View File

@ -205,6 +205,9 @@ func makeCertificate(certPEMBlock, keyPEMBlock []byte) (Certificate, error) {
//
// This function is safe for concurrent use.
func cacheCertificate(cert Certificate) {
if cert.Config == nil {
cert.Config = new(Config)
}
certCacheMu.Lock()
if _, ok := certCache[""]; !ok {
// use as default - must be *appended* to list, or bad things happen!

View File

@ -17,7 +17,7 @@ type Config struct {
// The hostname or class of hostnames this config is
// designated for; can contain wildcard characters
// according to RFC 6125 §6.4.3 - this field MUST
// NOT be empty in order for things to work smoothly
// be set in order for things to work as expected
Hostname string
// Whether TLS is enabled