@@ -2418,7 +2418,15 @@ func HandleFunc(pattern string, handler func(ResponseWriter, *Request)) {
2418
2418
// Serve accepts incoming HTTP connections on the listener l,
2419
2419
// creating a new service goroutine for each. The service goroutines
2420
2420
// 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.
2422
2430
func Serve (l net.Listener , handler Handler ) error {
2423
2431
srv := & Server {Handler : handler }
2424
2432
return srv .Serve (l )
@@ -2792,10 +2800,9 @@ var ErrServerClosed = errors.New("http: Server closed")
2792
2800
// new service goroutine for each. The service goroutines read requests and
2793
2801
// then call srv.Handler to reply to them.
2794
2802
//
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.
2799
2806
//
2800
2807
// Serve always returns a non-nil error and closes l.
2801
2808
// After Shutdown or Close, the returned error is ErrServerClosed.
@@ -2850,19 +2857,19 @@ func (srv *Server) Serve(l net.Listener) error {
2850
2857
}
2851
2858
2852
2859
// 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.
2855
2862
//
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.
2861
2869
//
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.
2866
2873
//
2867
2874
// ServeTLS always returns a non-nil error. After Shutdown or Close, the
2868
2875
// returned error is ErrServerClosed.
@@ -3072,7 +3079,8 @@ func ListenAndServeTLS(addr, certFile, keyFile string, handler Handler) error {
3072
3079
//
3073
3080
// If srv.Addr is blank, ":https" is used.
3074
3081
//
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.
3076
3084
func (srv * Server ) ListenAndServeTLS (certFile , keyFile string ) error {
3077
3085
if srv .shuttingDown () {
3078
3086
return ErrServerClosed
0 commit comments