Browse Source

Advertise 'h2' protocol, now that HTTP/2 is final.

We still advertise h2-14 too for a bit.

Update #29
Brad Fitzpatrick 11 years ago
parent
commit
13dfd89112
3 changed files with 10 additions and 3 deletions
  1. 1 1
      http2.go
  2. 6 1
      server.go
  3. 3 1
      server_test.go

+ 1 - 1
http2.go

@@ -38,7 +38,7 @@ const (
 
 
 	// NextProtoTLS is the NPN/ALPN protocol negotiated during
 	// NextProtoTLS is the NPN/ALPN protocol negotiated during
 	// HTTP/2's TLS setup.
 	// HTTP/2's TLS setup.
-	NextProtoTLS = "h2-14"
+	NextProtoTLS = "h2"
 
 
 	// http://http2.github.io/http2-spec/#SettingValues
 	// http://http2.github.io/http2-spec/#SettingValues
 	initialHeaderTableSize = 4096
 	initialHeaderTableSize = 4096

+ 6 - 1
server.go

@@ -175,16 +175,21 @@ func ConfigureServer(s *http.Server, conf *Server) {
 	if !haveNPN {
 	if !haveNPN {
 		s.TLSConfig.NextProtos = append(s.TLSConfig.NextProtos, NextProtoTLS)
 		s.TLSConfig.NextProtos = append(s.TLSConfig.NextProtos, NextProtoTLS)
 	}
 	}
+	// h2-14 is temporary (as of 2015-03-05) while we wait for all browsers
+	// to switch to "h2".
+	s.TLSConfig.NextProtos = append(s.TLSConfig.NextProtos, "h2-14")
 
 
 	if s.TLSNextProto == nil {
 	if s.TLSNextProto == nil {
 		s.TLSNextProto = map[string]func(*http.Server, *tls.Conn, http.Handler){}
 		s.TLSNextProto = map[string]func(*http.Server, *tls.Conn, http.Handler){}
 	}
 	}
-	s.TLSNextProto[NextProtoTLS] = func(hs *http.Server, c *tls.Conn, h http.Handler) {
+	protoHandler := func(hs *http.Server, c *tls.Conn, h http.Handler) {
 		if testHookOnConn != nil {
 		if testHookOnConn != nil {
 			testHookOnConn()
 			testHookOnConn()
 		}
 		}
 		conf.handleConn(hs, c, h)
 		conf.handleConn(hs, c, h)
 	}
 	}
+	s.TLSNextProto[NextProtoTLS] = protoHandler
+	s.TLSNextProto["h2-14"] = protoHandler // temporary; see above.
 }
 }
 
 
 func (srv *Server) handleConn(hs *http.Server, c net.Conn, h http.Handler) {
 func (srv *Server) handleConn(hs *http.Server, c net.Conn, h http.Handler) {

+ 3 - 1
server_test.go

@@ -76,7 +76,9 @@ func newServerTester(t testing.TB, handler http.HandlerFunc, opts ...interface{}
 
 
 	tlsConfig := &tls.Config{
 	tlsConfig := &tls.Config{
 		InsecureSkipVerify: true,
 		InsecureSkipVerify: true,
-		NextProtos:         []string{NextProtoTLS},
+		// The h2-14 is temporary, until curl is updated. (as used by unit tests
+		// in Docker)
+		NextProtos: []string{NextProtoTLS, "h2-14"},
 	}
 	}
 
 
 	onlyServer := false
 	onlyServer := false