]> Cypherpunks repositories - gostls13.git/commitdiff
http: add Server.ListenAndServeTLS
authorBrad Fitzpatrick <bradfitz@golang.org>
Mon, 20 Jun 2011 19:19:26 +0000 (12:19 -0700)
committerBrad Fitzpatrick <bradfitz@golang.org>
Mon, 20 Jun 2011 19:19:26 +0000 (12:19 -0700)
Fixes #1964

R=rsc
CC=golang-dev
https://golang.org/cl/4630045

src/pkg/http/server.go

index ac5487fd53ac2641c27fdc011c2c13cf18d07669..bb47430260606c6131f7023062471fa7fb92fc61 100644 (file)
@@ -908,7 +908,9 @@ func ListenAndServe(addr string, handler Handler) os.Error {
 
 // ListenAndServeTLS acts identically to ListenAndServe, except that it
 // expects HTTPS connections. Additionally, files containing a certificate and
-// matching private key for the server must be provided.
+// matching private key for the server must be provided. If the certificate
+// is signed by a certificate authority, the certFile should be the concatenation
+// of the server's certificate followed by the CA's certificate.
 //
 // A trivial example server is:
 //
@@ -933,6 +935,24 @@ func ListenAndServe(addr string, handler Handler) os.Error {
 //
 // One can use generate_cert.go in crypto/tls to generate cert.pem and key.pem.
 func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Handler) os.Error {
+       server := &Server{Addr: addr, Handler: handler}
+       return server.ListenAndServeTLS(certFile, keyFile)
+}
+
+// ListenAndServeTLS listens on the TCP network address srv.Addr and
+// then calls Serve to handle requests on incoming TLS connections.
+//
+// Filenames containing a certificate and matching private key for
+// the server must be provided. If the certificate is signed by a
+// certificate authority, the certFile should be the concatenation
+// of the server's certificate followed by the CA's certificate.
+//
+// If srv.Addr is blank, ":https" is used.
+func (s *Server) ListenAndServeTLS(certFile, keyFile string) os.Error {
+       addr := s.Addr
+       if addr == "" {
+               addr = ":https"
+       }
        config := &tls.Config{
                Rand:       rand.Reader,
                Time:       time.Seconds,
@@ -952,7 +972,7 @@ func ListenAndServeTLS(addr string, certFile string, keyFile string, handler Han
        }
 
        tlsListener := tls.NewListener(conn, config)
-       return Serve(tlsListener, handler)
+       return s.Serve(tlsListener)
 }
 
 // TimeoutHandler returns a Handler that runs h with the given time limit.