Skip to content

Commit 214f7ec

Browse files
committed
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 <iant@golang.org>
1 parent 62f401b commit 214f7ec

File tree

1 file changed

+25
-17
lines changed

1 file changed

+25
-17
lines changed

src/net/http/server.go

+25-17
Original file line numberDiff line numberDiff line change
@@ -2418,7 +2418,15 @@ func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) {
24182418
// Serve accepts incoming HTTP connections on the listener l,
24192419
// creating a new service goroutine for each. The service goroutines
24202420
// read requests and then call handler to reply to them.
2421-
// Handler is typically nil, in which case the DefaultServeMux is used.
2421+
//
2422+
// The handler is typically nil, in which case the DefaultServeMux is
2423+
// used.
2424+
//
2425+
// HTTP/2 support is only enabled if the Listener returns *tls.Conn
2426+
// connections and they were configured with "h2" in the TLS
2427+
// Config.NextProtos.
2428+
//
2429+
// Serve always returns a non-nil reror.
24222430
func Serve(l net.Listener, handler Handler) error {
24232431
srv := &Server{Handler: handler}
24242432
return srv.Serve(l)
@@ -2792,10 +2800,9 @@ var ErrServerClosed = errors.New("http: Server closed")
27922800
// new service goroutine for each. The service goroutines read requests and
27932801
// then call srv.Handler to reply to them.
27942802
//
2795-
// For HTTP/2 support, srv.TLSConfig should be initialized to the
2796-
// provided listener's TLS Config before calling Serve. If
2797-
// srv.TLSConfig is non-nil and doesn't include the string "h2" in
2798-
// Config.NextProtos, HTTP/2 support is not enabled.
2803+
// HTTP/2 support is only enabled if the Listener returns *tls.Conn
2804+
// connections and they were configured with "h2" in the TLS
2805+
// Config.NextProtos.
27992806
//
28002807
// Serve always returns a non-nil error and closes l.
28012808
// After Shutdown or Close, the returned error is ErrServerClosed.
@@ -2850,19 +2857,19 @@ func (srv *Server) Serve(l net.Listener) error {
28502857
}
28512858

28522859
// ServeTLS accepts incoming connections on the Listener l, creating a
2853-
// new service goroutine for each. The service goroutines read requests and
2854-
// then call srv.Handler to reply to them.
2860+
// new service goroutine for each. The service goroutines perform TLS
2861+
// setup and then read requests, calling srv.Handler to reply to them.
28552862
//
2856-
// Additionally, files containing a certificate and matching private key for
2857-
// the server must be provided if neither the Server's TLSConfig.Certificates
2858-
// nor TLSConfig.GetCertificate are populated.. If the certificate is signed by
2859-
// a certificate authority, the certFile should be the concatenation of the
2860-
// server's certificate, any intermediates, and the CA's certificate.
2863+
// Files containing a certificate and matching private key for the
2864+
// server must be provided if neither the Server's
2865+
// TLSConfig.Certificates nor TLSConfig.GetCertificate are populated.
2866+
// If the certificate is signed by a certificate authority, the
2867+
// certFile should be the concatenation of the server's certificate,
2868+
// any intermediates, and the CA's certificate.
28612869
//
2862-
// For HTTP/2 support, srv.TLSConfig should be initialized to the
2863-
// provided listener's TLS Config before calling ServeTLS. If
2864-
// srv.TLSConfig is non-nil and doesn't include the string "h2" in
2865-
// Config.NextProtos, HTTP/2 support is not enabled.
2870+
// For HTTP/2 support, srv.TLSConfig should be initialized before
2871+
// calling ServeTLS and must contain the string "h2" in its NextProtos
2872+
// field.
28662873
//
28672874
// ServeTLS always returns a non-nil error. After Shutdown or Close, the
28682875
// returned error is ErrServerClosed.
@@ -3072,7 +3079,8 @@ func ListenAndServeTLS(addr, certFile, keyFile string, handler Handler) error {
30723079
//
30733080
// If srv.Addr is blank, ":https" is used.
30743081
//
3075-
// ListenAndServeTLS always returns a non-nil error.
3082+
// ListenAndServeTLS always returns a non-nil error. After Shutdown or
3083+
// Close, the returned error is ErrServerClosed.
30763084
func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error {
30773085
if srv.shuttingDown() {
30783086
return ErrServerClosed

0 commit comments

Comments
 (0)