From d41993b816f56a3f7874d4fb0198173b35062c3d Mon Sep 17 00:00:00 2001 From: fangdingjun Date: Mon, 2 Jul 2018 11:24:18 +0800 Subject: [PATCH] fix protocol error --- http2.go | 3 ++- http2_test.go | 13 ++++++++++++- nghttp2.c | 4 ++-- 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/http2.go b/http2.go index 944152a..b54a1d4 100644 --- a/http2.go +++ b/http2.go @@ -147,7 +147,7 @@ func (c *Conn) run() { errch := make(chan error) go func() { - buf := make([]byte, 4096) + buf := make([]byte, 16*1024) for { n, err := c.conn.Read(buf) if err != nil { @@ -186,6 +186,7 @@ loop: d1 := C.CBytes(d) ret1 := C.nghttp2_session_mem_recv(c.session, (*C.uchar)(d1), C.size_t(int(len(d)))) + C.free(d1) if int(ret1) < 0 { c.err = fmt.Errorf("sesion recv error: %s", C.GoString(C.nghttp2_strerror(ret))) diff --git a/http2_test.go b/http2_test.go index f31bd3d..6872d9c 100644 --- a/http2_test.go +++ b/http2_test.go @@ -32,7 +32,9 @@ func TestHttp2Client(t *testing.T) { param.Add("e", "b") param.Add("f", "d") data := bytes.NewReader([]byte(param.Encode())) - req, _ := http.NewRequest("POST", "https://www.simicloud.com/media/httpbin/post?a=b&c=d", data) + req, _ := http.NewRequest("POST", + "https://www.simicloud.com/media/httpbin/post?a=b&c=d", + data) log.Printf("%+v", req) req.Header.Set("accept", "*/*") req.Header.Set("user-agent", "go-nghttp2/1.0") @@ -42,5 +44,14 @@ func TestHttp2Client(t *testing.T) { t.Fatal(err) } res.Write(os.Stderr) + + req, _ = http.NewRequest("GET", + "https://www.simicloud.com/media/httpbin/get?a=b&c=d", nil) + res, err = h2conn.CreateRequest(req) + if err != nil { + t.Fatal(err) + } + res.Write(os.Stderr) + log.Println("end") } diff --git a/nghttp2.c b/nghttp2.c index 657b3da..06d86fd 100644 --- a/nghttp2.c +++ b/nghttp2.c @@ -164,7 +164,7 @@ void init_callbacks(nghttp2_session_callbacks *callbacks) nghttp2_session_callbacks_set_send_callback(callbacks, send_callback); nghttp2_session_callbacks_set_recv_callback(callbacks, recv_callback); - nghttp2_session_callbacks_set_error_callback2(callbacks, on_error_callback); + //nghttp2_session_callbacks_set_error_callback2(callbacks, on_error_callback); nghttp2_session_callbacks_set_on_invalid_frame_recv_callback(callbacks, on_invalid_frame_recv_callback); nghttp2_session_callbacks_set_on_frame_recv_callback(callbacks, on_frame_recv_callback); @@ -190,7 +190,7 @@ nghttp2_session *init_client_session(size_t data) nghttp2_session_callbacks *callbacks; nghttp2_session_callbacks_new(&callbacks); init_callbacks(callbacks); - ret = nghttp2_session_server_new(&session, callbacks, (void *)((int *)(data))); + ret = nghttp2_session_client_new(&session, callbacks, (void *)((int *)(data))); if (session == NULL) { printf("c init session failed: %s\n", nghttp2_strerror(ret));