Commit 214f7ec5 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

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/125515Reviewed-by: default avatarIan Lance Taylor <iant@golang.org>
parent 62f401bf
...@@ -2418,7 +2418,15 @@ func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) { ...@@ -2418,7 +2418,15 @@ func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) {
// Serve accepts incoming HTTP connections on the listener l, // Serve accepts incoming HTTP connections on the listener l,
// creating a new service goroutine for each. The service goroutines // creating a new service goroutine for each. The service goroutines
// read requests and then call handler to reply to them. // 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 { func Serve(l net.Listener, handler Handler) error {
srv := &Server{Handler: handler} srv := &Server{Handler: handler}
return srv.Serve(l) return srv.Serve(l)
...@@ -2792,10 +2800,9 @@ var ErrServerClosed = errors.New("http: Server closed") ...@@ -2792,10 +2800,9 @@ var ErrServerClosed = errors.New("http: Server closed")
// new service goroutine for each. The service goroutines read requests and // new service goroutine for each. The service goroutines read requests and
// then call srv.Handler to reply to them. // then call srv.Handler to reply to them.
// //
// For HTTP/2 support, srv.TLSConfig should be initialized to the // HTTP/2 support is only enabled if the Listener returns *tls.Conn
// provided listener's TLS Config before calling Serve. If // connections and they were configured with "h2" in the TLS
// srv.TLSConfig is non-nil and doesn't include the string "h2" in // Config.NextProtos.
// Config.NextProtos, HTTP/2 support is not enabled.
// //
// Serve always returns a non-nil error and closes l. // Serve always returns a non-nil error and closes l.
// After Shutdown or Close, the returned error is ErrServerClosed. // After Shutdown or Close, the returned error is ErrServerClosed.
...@@ -2850,19 +2857,19 @@ func (srv *Server) Serve(l net.Listener) error { ...@@ -2850,19 +2857,19 @@ func (srv *Server) Serve(l net.Listener) error {
} }
// ServeTLS accepts incoming connections on the Listener l, creating a // ServeTLS accepts incoming connections on the Listener l, creating a
// new service goroutine for each. The service goroutines read requests and // new service goroutine for each. The service goroutines perform TLS
// then call srv.Handler to reply to them. // setup and then read requests, calling srv.Handler to reply to them.
// //
// Additionally, files containing a certificate and matching private key for // Files containing a certificate and matching private key for the
// the server must be provided if neither the Server's TLSConfig.Certificates // server must be provided if neither the Server's
// nor TLSConfig.GetCertificate are populated.. If the certificate is signed by // TLSConfig.Certificates nor TLSConfig.GetCertificate are populated.
// a certificate authority, the certFile should be the concatenation of the // If the certificate is signed by a certificate authority, the
// server's certificate, any intermediates, and the CA's certificate. // 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 // For HTTP/2 support, srv.TLSConfig should be initialized before
// provided listener's TLS Config before calling ServeTLS. If // calling ServeTLS and must contain the string "h2" in its NextProtos
// srv.TLSConfig is non-nil and doesn't include the string "h2" in // field.
// Config.NextProtos, HTTP/2 support is not enabled.
// //
// ServeTLS always returns a non-nil error. After Shutdown or Close, the // ServeTLS always returns a non-nil error. After Shutdown or Close, the
// returned error is ErrServerClosed. // returned error is ErrServerClosed.
...@@ -3072,7 +3079,8 @@ func ListenAndServeTLS(addr, certFile, keyFile string, handler Handler) error { ...@@ -3072,7 +3079,8 @@ func ListenAndServeTLS(addr, certFile, keyFile string, handler Handler) error {
// //
// If srv.Addr is blank, ":https" is used. // 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 { func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error {
if srv.shuttingDown() { if srv.shuttingDown() {
return ErrServerClosed return ErrServerClosed
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment