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