Commit 6da300b1 authored by Brad Fitzpatrick's avatar Brad Fitzpatrick

net/http: remove references to old NPN support

We now only support ALPN.

Updates #28362

Change-Id: I8d9461c7a91315ee92e712448d0bf5c4070d09ae
Reviewed-on: https://go-review.googlesource.com/c/go/+/201202
Run-TryBot: Brad Fitzpatrick <bradfitz@golang.org>
Run-TryBot: Bryan C. Mills <bcmills@google.com>
Reviewed-by: default avatarBryan C. Mills <bcmills@google.com>
Reviewed-by: default avatarFilippo Valsorda <filippo@golang.org>
TryBot-Result: Gobot Gobot <gobot@golang.org>
parent e7394e17
...@@ -1696,11 +1696,10 @@ func (c *conn) closeWriteAndWait() { ...@@ -1696,11 +1696,10 @@ func (c *conn) closeWriteAndWait() {
time.Sleep(rstAvoidanceDelay) time.Sleep(rstAvoidanceDelay)
} }
// validNPN reports whether the proto is not a blacklisted Next // validNextProto reports whether the proto is not a blacklisted ALPN
// Protocol Negotiation protocol. Empty and built-in protocol types // protocol name. Empty and built-in protocol types are blacklisted
// are blacklisted and can't be overridden with alternate // and can't be overridden with alternate implementations.
// implementations. func validNextProto(proto string) bool {
func validNPN(proto string) bool {
switch proto { switch proto {
case "", "http/1.1", "http/1.0": case "", "http/1.1", "http/1.0":
return false return false
...@@ -1799,9 +1798,9 @@ func (c *conn) serve(ctx context.Context) { ...@@ -1799,9 +1798,9 @@ func (c *conn) serve(ctx context.Context) {
} }
c.tlsState = new(tls.ConnectionState) c.tlsState = new(tls.ConnectionState)
*c.tlsState = tlsConn.ConnectionState() *c.tlsState = tlsConn.ConnectionState()
if proto := c.tlsState.NegotiatedProtocol; validNPN(proto) { if proto := c.tlsState.NegotiatedProtocol; validNextProto(proto) {
if fn := c.server.TLSNextProto[proto]; fn != nil { if fn := c.server.TLSNextProto[proto]; fn != nil {
h := initNPNRequest{ctx, tlsConn, serverHandler{c.server}} h := initALPNRequest{ctx, tlsConn, serverHandler{c.server}}
fn(c.server, tlsConn, h) fn(c.server, tlsConn, h)
} }
return return
...@@ -2547,7 +2546,7 @@ type Server struct { ...@@ -2547,7 +2546,7 @@ type Server struct {
MaxHeaderBytes int MaxHeaderBytes int
// TLSNextProto optionally specifies a function to take over // TLSNextProto optionally specifies a function to take over
// ownership of the provided TLS connection when an NPN/ALPN // ownership of the provided TLS connection when an ALPN
// protocol upgrade has occurred. The map key is the protocol // protocol upgrade has occurred. The map key is the protocol
// name negotiated. The Handler argument should be used to // name negotiated. The Handler argument should be used to
// handle HTTP requests and will initialize the Request's TLS // handle HTTP requests and will initialize the Request's TLS
...@@ -2697,7 +2696,7 @@ func (srv *Server) Shutdown(ctx context.Context) error { ...@@ -2697,7 +2696,7 @@ func (srv *Server) Shutdown(ctx context.Context) error {
// RegisterOnShutdown registers a function to call on Shutdown. // RegisterOnShutdown registers a function to call on Shutdown.
// This can be used to gracefully shutdown connections that have // This can be used to gracefully shutdown connections that have
// undergone NPN/ALPN protocol upgrade or that have been hijacked. // undergone ALPN protocol upgrade or that have been hijacked.
// This function should start protocol-specific graceful shutdown, // This function should start protocol-specific graceful shutdown,
// but should not wait for shutdown to complete. // but should not wait for shutdown to complete.
func (srv *Server) RegisterOnShutdown(f func()) { func (srv *Server) RegisterOnShutdown(f func()) {
...@@ -3346,10 +3345,10 @@ func (globalOptionsHandler) ServeHTTP(w ResponseWriter, r *Request) { ...@@ -3346,10 +3345,10 @@ func (globalOptionsHandler) ServeHTTP(w ResponseWriter, r *Request) {
} }
} }
// initNPNRequest is an HTTP handler that initializes certain // initALPNRequest is an HTTP handler that initializes certain
// uninitialized fields in its *Request. Such partially-initialized // uninitialized fields in its *Request. Such partially-initialized
// Requests come from NPN protocol handlers. // Requests come from ALPN protocol handlers.
type initNPNRequest struct { type initALPNRequest struct {
ctx context.Context ctx context.Context
c *tls.Conn c *tls.Conn
h serverHandler h serverHandler
...@@ -3359,9 +3358,9 @@ type initNPNRequest struct { ...@@ -3359,9 +3358,9 @@ type initNPNRequest struct {
// recognized by x/net/http2 to pass down a context; the TLSNextProto // recognized by x/net/http2 to pass down a context; the TLSNextProto
// API predates context support so we shoehorn through the only // API predates context support so we shoehorn through the only
// interface we have available. // interface we have available.
func (h initNPNRequest) BaseContext() context.Context { return h.ctx } func (h initALPNRequest) BaseContext() context.Context { return h.ctx }
func (h initNPNRequest) ServeHTTP(rw ResponseWriter, req *Request) { func (h initALPNRequest) ServeHTTP(rw ResponseWriter, req *Request) {
if req.TLS == nil { if req.TLS == nil {
req.TLS = &tls.ConnectionState{} req.TLS = &tls.ConnectionState{}
*req.TLS = h.c.ConnectionState() *req.TLS = h.c.ConnectionState()
......
...@@ -218,7 +218,7 @@ type Transport struct { ...@@ -218,7 +218,7 @@ type Transport struct {
ExpectContinueTimeout time.Duration ExpectContinueTimeout time.Duration
// TLSNextProto specifies how the Transport switches to an // TLSNextProto specifies how the Transport switches to an
// alternate protocol (such as HTTP/2) after a TLS NPN/ALPN // alternate protocol (such as HTTP/2) after a TLS ALPN
// protocol negotiation. If Transport dials an TLS connection // protocol negotiation. If Transport dials an TLS connection
// with a non-empty protocol name and TLSNextProto contains a // with a non-empty protocol name and TLSNextProto contains a
// map entry for that key (such as "h2"), then the func is // map entry for that key (such as "h2"), then the func is
......
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