Browse Source

Set npnProto (also ALPN) to 'h2-14', add test hook.

Brad Fitzpatrick 11 years ago
parent
commit
e04676d991
2 changed files with 18 additions and 2 deletions
  1. 6 1
      http2.go
  2. 12 1
      http2_test.go

+ 6 - 1
http2.go

@@ -30,7 +30,7 @@ var (
 	clientPreface = []byte(ClientPreface)
 	clientPreface = []byte(ClientPreface)
 )
 )
 
 
-const npnProto = "h2-13"
+const npnProto = "h2-14"
 
 
 // Server is an HTTP2 server.
 // Server is an HTTP2 server.
 type Server struct {
 type Server struct {
@@ -132,6 +132,11 @@ func ConfigureServer(s *http.Server, conf *Server) {
 		s.TLSNextProto = map[string]func(*http.Server, *tls.Conn, http.Handler){}
 		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[npnProto] = func(hs *http.Server, c *tls.Conn, h http.Handler) {
+		if testHookOnConn != nil {
+			testHookOnConn()
+		}
 		conf.handleClientConn(hs, c, h)
 		conf.handleClientConn(hs, c, h)
 	}
 	}
 }
 }
+
+var testHookOnConn func() // for testing

+ 12 - 1
http2_test.go

@@ -13,6 +13,7 @@ import (
 	"net/http/httptest"
 	"net/http/httptest"
 	"os/exec"
 	"os/exec"
 	"strings"
 	"strings"
+	"sync/atomic"
 	"testing"
 	"testing"
 )
 )
 
 
@@ -23,13 +24,23 @@ func TestServer(t *testing.T) {
 		io.WriteString(w, "Hello, test.")
 		io.WriteString(w, "Hello, test.")
 	}))
 	}))
 	ConfigureServer(ts.Config, &Server{})
 	ConfigureServer(ts.Config, &Server{})
+	ts.TLS = ts.Config.TLSConfig // the httptest.Server has its own copy of this TLS config
 	ts.StartTLS()
 	ts.StartTLS()
 	defer ts.Close()
 	defer ts.Close()
-	out, err := curl(t, "--http2", "--insecure", "-v", ts.URL).CombinedOutput()
+
+	var gotConn int32
+	testHookOnConn = func() { atomic.StoreInt32(&gotConn, 1) }
+
+	t.Logf("Running curl on %s", ts.URL)
+	out, err := curl(t, "--silent", "--http2", "--insecure", "-v", ts.URL).CombinedOutput()
 	if err != nil {
 	if err != nil {
 		t.Fatalf("Error fetching with curl: %v, %s", err, out)
 		t.Fatalf("Error fetching with curl: %v, %s", err, out)
 	}
 	}
 	t.Logf("Got: %s", out)
 	t.Logf("Got: %s", out)
+
+	if atomic.LoadInt32(&gotConn) == 0 {
+		t.Error("never saw an http2 connection")
+	}
 }
 }
 
 
 // Verify that curl has http2.
 // Verify that curl has http2.