From abe4e4956f716cf3d4a1596073bf8a6183aee8c0 Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Sat, 30 Jun 2018 21:47:45 +0800 Subject: [PATCH] add http2 test --- http2_test.go | 34 ++++++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) create mode 100644 http2_test.go diff --git a/http2_test.go b/http2_test.go new file mode 100644 index 0000000..34a8425 --- /dev/null +++ b/http2_test.go @@ -0,0 +1,34 @@ +package nghttp2 + +import ( + "crypto/tls" + "net/http" + "os" + "testing" +) + +func TestHttp2Client(t *testing.T) { + conn, err := tls.Dial("tcp", "www.simicloud.com:443", &tls.Config{ + NextProtos: []string{"h2"}, + ServerName: "www.simicloud.com", + }) + if err != nil { + t.Fatal(err) + } + defer conn.Close() + + cstate := conn.ConnectionState() + if cstate.NegotiatedProtocol != "h2" { + t.Fatal("no http2 on server") + } + h2conn, err := NewConn(conn) + if err != nil { + t.Fatal(err) + } + req, _ := http.NewRequest("GET", "http://www.simicloud.com/media/httpbin/get", nil) + res, err := h2conn.NewRequest(req) + if err != nil { + t.Fatal(err) + } + res.Write(os.Stderr) +}