diff --git a/tests/main.c b/tests/main.c index 3319d6a9..d7780326 100644 --- a/tests/main.c +++ b/tests/main.c @@ -139,6 +139,10 @@ int main(int argc, char* argv[]) test_nghttp2_submit_request2_with_data) || !CU_add_test(pSuite, "submit_request2_without_data", test_nghttp2_submit_request2_without_data) || + !CU_add_test(pSuite, "submit_response2_with_data", + test_nghttp2_submit_response2_with_data) || + !CU_add_test(pSuite, "submit_response2_without_data", + test_nghttp2_submit_response2_without_data) || !CU_add_test(pSuite, "submit_headers_start_stream", test_nghttp2_submit_headers_start_stream) || !CU_add_test(pSuite, "submit_headers_reply", diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index b5955daa..e70bb9ee 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -2073,6 +2073,73 @@ void test_nghttp2_submit_request2_without_data(void) nghttp2_session_del(session); } +void test_nghttp2_submit_response2_with_data(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + nghttp2_nv nva[] = {MAKE_NV(":version", "HTTP/1.1")}; + nghttp2_data_provider data_prd; + my_user_data ud; + nghttp2_outbound_item *item; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + + data_prd.read_callback = fixed_length_data_source_read_callback; + ud.data_source_length = 64*1024 - 1; + CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_END_STREAM, + NGHTTP2_PRI_DEFAULT, + NGHTTP2_STREAM_OPENING, NULL); + CU_ASSERT(0 == nghttp2_submit_response2(session, 1, nva, ARRLEN(nva), + &data_prd)); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0])); + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(0 == ud.data_source_length); + + nghttp2_session_del(session); +} + +void test_nghttp2_submit_response2_without_data(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + accumulator acc; + nghttp2_nv nva[] = {MAKE_NV(":version", "HTTP/1.1")}; + nghttp2_data_provider data_prd = {{-1}, NULL}; + nghttp2_outbound_item *item; + my_user_data ud; + nghttp2_frame frame; + nghttp2_hd_context inflater; + + acc.length = 0; + ud.acc = &acc; + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = accumulator_send_callback; + CU_ASSERT(0 == nghttp2_session_server_new(&session, &callbacks, &ud)); + nghttp2_hd_inflate_init(&inflater, NGHTTP2_HD_SIDE_RESPONSE); + nghttp2_session_open_stream(session, 1, NGHTTP2_FLAG_END_STREAM, + NGHTTP2_PRI_DEFAULT, + NGHTTP2_STREAM_OPENING, NULL); + CU_ASSERT(0 == nghttp2_submit_response2(session, 1, nva, ARRLEN(nva), + &data_prd)); + item = nghttp2_session_get_next_ob_item(session); + CU_ASSERT(nvnameeq(":version", &OB_CTRL(item)->headers.nva[0])); + CU_ASSERT(OB_CTRL(item)->hd.flags & NGHTTP2_FLAG_END_STREAM); + + CU_ASSERT(0 == nghttp2_session_send(session)); + CU_ASSERT(0 == unpack_frame_with_nv_block(&frame, NGHTTP2_HEADERS, + &inflater, + acc.buf, acc.length)); + CU_ASSERT(nvnameeq(":version", &frame.headers.nva[0])); + nghttp2_frame_headers_free(&frame.headers); + nghttp2_hd_end_headers(&inflater); + + nghttp2_hd_inflate_free(&inflater); + nghttp2_session_del(session); +} + void test_nghttp2_submit_headers_start_stream(void) { nghttp2_session *session; diff --git a/tests/nghttp2_session_test.h b/tests/nghttp2_session_test.h index 796cd071..ec4a11c7 100644 --- a/tests/nghttp2_session_test.h +++ b/tests/nghttp2_session_test.h @@ -59,6 +59,8 @@ void test_nghttp2_submit_request_with_data(void); void test_nghttp2_submit_request_without_data(void); void test_nghttp2_submit_request2_with_data(void); void test_nghttp2_submit_request2_without_data(void); +void test_nghttp2_submit_response2_with_data(void); +void test_nghttp2_submit_response2_without_data(void); void test_nghttp2_submit_headers_start_stream(void); void test_nghttp2_submit_headers_reply(void); void test_nghttp2_submit_headers_push_reply(void);