diff options
| author | Brad Fitzpatrick <bradfitz@golang.org> | 2015-10-14 20:41:36 +0000 |
|---|---|---|
| committer | Brad Fitzpatrick <bradfitz@golang.org> | 2015-10-14 23:21:57 +0000 |
| commit | 20736fcab966412cb41b8a3c9a051469a5c8f00c (patch) | |
| tree | b68b3c9fcdd490ed39d475988983d646552bbe4b /src/net/http/server.go | |
| parent | 7a3dcd2d0f3e311e6f18edf841862ad4b8f90b51 (diff) | |
| download | go-20736fcab966412cb41b8a3c9a051469a5c8f00c.tar.xz | |
net/http: enable automatic HTTP/2 if TLSNextProto is nil
This enables HTTP/2 by default (for https only) if the user didn't
configure anything in their NPN/ALPN map. If they're using SPDY or an
alternate http2 or a newer http2 from x/net/http2, we do nothing
and don't use the standard library's vendored copy of x/net/http2.
Upstream remains golang.org/x/net/http2.
Update #6891
Change-Id: I69a8957a021a00ac353f9d7fdb9a40a5b69f2199
Reviewed-on: https://go-review.googlesource.com/15828
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Reviewed-by: Andrew Gerrand <adg@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/net/http/server.go')
| -rw-r--r-- | src/net/http/server.go | 12 |
1 files changed, 11 insertions, 1 deletions
diff --git a/src/net/http/server.go b/src/net/http/server.go index ae62e076dd..dc4f100e01 100644 --- a/src/net/http/server.go +++ b/src/net/http/server.go @@ -1806,7 +1806,8 @@ type Server struct { // standard logger. ErrorLog *log.Logger - disableKeepAlives int32 // accessed atomically. + disableKeepAlives int32 // accessed atomically. + nextProtoOnce sync.Once // guards initialization of TLSNextProto in Serve } // A ConnState represents the state of a client connection to a server. @@ -1896,6 +1897,7 @@ func (srv *Server) ListenAndServe() error { func (srv *Server) Serve(l net.Listener) error { defer l.Close() var tempDelay time.Duration // how long to sleep on accept failure + srv.nextProtoOnce.Do(srv.setNextProtoDefaults) for { rw, e := l.Accept() if e != nil { @@ -2052,6 +2054,14 @@ func (srv *Server) ListenAndServeTLS(certFile, keyFile string) error { return srv.Serve(tlsListener) } +func (srv *Server) setNextProtoDefaults() { + // Enable HTTP/2 by default if the user hasn't otherwise + // configured their TLSNextProto map. + if srv.TLSNextProto == nil { + http2ConfigureServer(srv, nil) + } +} + // TimeoutHandler returns a Handler that runs h with the given time limit. // // The new Handler calls h.ServeHTTP to handle each request, but if a |
