From 214f7ec554888042a7a54fdca9cba19aee8ebaf1 Mon Sep 17 00:00:00 2001 From: Brad Fitzpatrick Date: Mon, 23 Jul 2018 18:31:23 +0000 Subject: [PATCH] net/http: update Serve docs on when HTTP/2 is enabled Contains portions and modified portions of CL 103815 Fixes #24607 Change-Id: Ic330850a0f098f183315f04ea4780eded46c5b77 Reviewed-on: https://go-review.googlesource.com/125515 Reviewed-by: Ian Lance Taylor --- src/net/http/server.go | 42 +++++++++++++++++++++++++----------------- 1 file changed, 25 insertions(+), 17 deletions(-) diff --git a/src/net/http/server.go b/src/net/http/server.go index ce785a3916..91caca7267 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -2418,7 +2418,15 @@ func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) { // Serve accepts incoming HTTP connections on the listener l, // creating a new service goroutine for each. The service goroutines // read requests and then call handler to reply to them. -// Handler is typically nil, in which case the DefaultServeMux is used. +// +// The handler is typically nil, in which case the DefaultServeMux is +// used. +// +// HTTP/2 support is only enabled if the Listener returns *tls.Conn +// connections and they were configured with "h2" in the TLS +// Config.NextProtos. +// +// Serve always returns a non-nil reror. func Serve(l net.Listener, handler Handler) error { srv := &Server{Handler: handler} return srv.Serve(l) @@ -2792,10 +2800,9 @@ var ErrServerClosed = errors.New("http: Server closed") // new service goroutine for each. The service goroutines read requests and // then call srv.Handler to reply to them. // -// For HTTP/2 support, srv.TLSConfig should be initialized to the -// provided listener's TLS Config before calling Serve. If -// srv.TLSConfig is non-nil and doesn't include the string "h2" in -// Config.NextProtos, HTTP/2 support is not enabled. +// HTTP/2 support is only enabled if the Listener returns *tls.Conn +// connections and they were configured with "h2" in the TLS +// Config.NextProtos. // // Serve always returns a non-nil error and closes l. // After Shutdown or Close, the returned error is ErrServerClosed. @@ -2850,19 +2857,19 @@ func (srv *Server) Serve(l net.Listener) error { } // ServeTLS accepts incoming connections on the Listener l, creating a -// new service goroutine for each. The service goroutines read requests and -// then call srv.Handler to reply to them. +// new service goroutine for each. The service goroutines perform TLS +// setup and then read requests, calling srv.Handler to reply to them. // -// Additionally, files containing a certificate and matching private key for -// the server must be provided if neither the Server's TLSConfig.Certificates -// nor TLSConfig.GetCertificate are populated.. If the certificate is signed by -// a certificate authority, the certFile should be the concatenation of the -// server's certificate, any intermediates, and the CA's certificate. +// Files containing a certificate and matching private key for the +// server must be provided if neither the Server's +// TLSConfig.Certificates nor TLSConfig.GetCertificate are populated. +// If the certificate is signed by a certificate authority, the +// certFile should be the concatenation of the server's certificate, +// any intermediates, and the CA's certificate. // -// For HTTP/2 support, srv.TLSConfig should be initialized to the -// provided listener's TLS Config before calling ServeTLS. If -// srv.TLSConfig is non-nil and doesn't include the string "h2" in -// Config.NextProtos, HTTP/2 support is not enabled. +// For HTTP/2 support, srv.TLSConfig should be initialized before +// calling ServeTLS and must contain the string "h2" in its NextProtos +// field. // // ServeTLS always returns a non-nil error. After Shutdown or Close, the // returned error is ErrServerClosed. @@ -3072,7 +3079,8 @@ func ListenAndServeTLS(addr, certFile, keyFile string, handler Handler) error { // // If srv.Addr is blank, ":https" is used. // -// ListenAndServeTLS always returns a non-nil error. +// ListenAndServeTLS always returns a non-nil error. After Shutdown or +// Close, the returned error is ErrServerClosed. func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error { if srv.shuttingDown() { return ErrServerClosed -- 2.48.1