Browse Source

Export the NPN/ALPN protocol constant

Brad Fitzpatrick 11 years ago
parent
commit
36d9a67b6d
3 changed files with 7 additions and 5 deletions
  1. 3 1
      http2.go
  2. 3 3
      server.go
  3. 1 1
      server_test.go

+ 3 - 1
http2.go

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

+ 3 - 3
server.go

@@ -133,19 +133,19 @@ func ConfigureServer(s *http.Server, conf *Server) {
 	}
 	haveNPN := false
 	for _, p := range s.TLSConfig.NextProtos {
-		if p == npnProto {
+		if p == NextProtoTLS {
 			haveNPN = true
 			break
 		}
 	}
 	if !haveNPN {
-		s.TLSConfig.NextProtos = append(s.TLSConfig.NextProtos, npnProto)
+		s.TLSConfig.NextProtos = append(s.TLSConfig.NextProtos, NextProtoTLS)
 	}
 
 	if s.TLSNextProto == nil {
 		s.TLSNextProto = map[string]func(*http.Server, *tls.Conn, http.Handler){}
 	}
-	s.TLSNextProto[npnProto] = func(hs *http.Server, c *tls.Conn, h http.Handler) {
+	s.TLSNextProto[NextProtoTLS] = func(hs *http.Server, c *tls.Conn, h http.Handler) {
 		if testHookOnConn != nil {
 			testHookOnConn()
 		}

+ 1 - 1
server_test.go

@@ -71,7 +71,7 @@ func newServerTester(t *testing.T, handler http.HandlerFunc) *serverTester {
 	}
 	cc, err := tls.Dial("tcp", ts.Listener.Addr().String(), &tls.Config{
 		InsecureSkipVerify: true,
-		NextProtos:         []string{npnProto},
+		NextProtos:         []string{NextProtoTLS},
 	})
 	if err != nil {
 		t.Fatal(err)