|
|
|
@ -10,7 +10,7 @@ server usage example:
|
|
|
|
|
|
|
|
|
|
cert, err := tls.LoadX509KeyPair("testdata/server.crt", "testdata/server.key")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
l, err := tls.Listen("tcp", "127.0.0.1:1100", &tls.Config{
|
|
|
|
@ -18,7 +18,7 @@ server usage example:
|
|
|
|
|
NextProtos: []string{"h2"},
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer l.Close()
|
|
|
|
|
addr := l.Addr().String()
|
|
|
|
@ -30,7 +30,7 @@ server usage example:
|
|
|
|
|
hdr.Set("aa", "bb")
|
|
|
|
|
d, err := ioutil.ReadAll(r.Body)
|
|
|
|
|
if err != nil {
|
|
|
|
|
ln(err)
|
|
|
|
|
log.Println(err)
|
|
|
|
|
return
|
|
|
|
|
}
|
|
|
|
|
w.Write(d)
|
|
|
|
@ -43,7 +43,7 @@ server usage example:
|
|
|
|
|
}
|
|
|
|
|
h2conn, err := NewServerConn(c, nil)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
f("%+v", h2conn)
|
|
|
|
|
go h2conn.Run()
|
|
|
|
@ -57,18 +57,18 @@ client usage example:
|
|
|
|
|
ServerName: "nghttp2.org",
|
|
|
|
|
})
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
defer conn.Close()
|
|
|
|
|
|
|
|
|
|
cstate := conn.ConnectionState()
|
|
|
|
|
if cstate.NegotiatedProtocol != "h2" {
|
|
|
|
|
t.Fatal("no http2 on server")
|
|
|
|
|
log.Fatal("no http2 on server")
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
h2conn, err := NewClientConn(conn)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
param := url.Values{}
|
|
|
|
@ -79,18 +79,18 @@ client usage example:
|
|
|
|
|
"https://nghttp2.org/httpbin/post?a=b&c=d",
|
|
|
|
|
data)
|
|
|
|
|
|
|
|
|
|
f("%+v", req)
|
|
|
|
|
log.Printf("%+v", req)
|
|
|
|
|
|
|
|
|
|
req.Header.Set("user-agent", "go-nghttp2/1.0")
|
|
|
|
|
req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
|
|
|
|
|
|
|
|
|
|
res, err := h2conn.CreateRequest(req)
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if res.StatusCode != http.StatusOK {
|
|
|
|
|
t.Errorf("expect %d, got %d", http.StatusOK, res.StatusCode)
|
|
|
|
|
log.Printf("expect %d, got %d", http.StatusOK, res.StatusCode)
|
|
|
|
|
}
|
|
|
|
|
res.Write(os.Stderr)
|
|
|
|
|
|
|
|
|
@ -99,7 +99,7 @@ co-work with net/http server example:
|
|
|
|
|
|
|
|
|
|
l, err := net.Listen("tcp", "127.0.0.1:1222")
|
|
|
|
|
if err != nil {
|
|
|
|
|
t.Fatal(err)
|
|
|
|
|
log.Fatal(err)
|
|
|
|
|
}
|
|
|
|
|
srv := &http.Server{
|
|
|
|
|
TLSConfig: &tls.Config{
|
|
|
|
|