From b7ff05c4c66eaba36619c0ccb7664b0dee04a2b1 Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 23 Jul 2013 22:47:15 +0900 Subject: [PATCH] Fail session if header compression failed on send --- lib/nghttp2_session.c | 6 ++++++ tests/main.c | 2 ++ tests/nghttp2_session_test.c | 35 +++++++++++++++++++++++++++++++++++ tests/nghttp2_session_test.h | 1 + 4 files changed, 44 insertions(+) diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 2757b35f..be3eeffe 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -1290,6 +1290,12 @@ int nghttp2_session_send(nghttp2_session *session) nghttp2_outbound_item_free(item); free(item); + if(framebuflen == NGHTTP2_ERR_HEADER_COMP) { + // If header compression error occurred, should terminiate + // connection. + framebuflen = nghttp2_session_fail_session(session, + NGHTTP2_INTERNAL_ERROR); + } if(nghttp2_is_fatal(framebuflen)) { return framebuflen; } else { diff --git a/tests/main.c b/tests/main.c index 73497cea..b8f814f2 100644 --- a/tests/main.c +++ b/tests/main.c @@ -108,6 +108,8 @@ int main(int argc, char* argv[]) test_nghttp2_session_send_headers_start_stream) || !CU_add_test(pSuite, "session_send_headers_reply", test_nghttp2_session_send_headers_reply) || + !CU_add_test(pSuite, "session_send_headers_header_comp_error", + test_nghttp2_session_send_headers_header_comp_error) || !CU_add_test(pSuite, "session_send_priority", test_nghttp2_session_send_priority) || !CU_add_test(pSuite, "session_send_rst_stream", diff --git a/tests/nghttp2_session_test.c b/tests/nghttp2_session_test.c index cbef076a..e4526de8 100644 --- a/tests/nghttp2_session_test.c +++ b/tests/nghttp2_session_test.c @@ -1115,6 +1115,41 @@ void test_nghttp2_session_send_headers_reply(void) nghttp2_session_del(session); } +/* TODO Rewrite this test when header continuation is supported */ +void test_nghttp2_session_send_headers_header_comp_error(void) +{ + nghttp2_session *session; + nghttp2_session_callbacks callbacks; + const char *nv[] = { ":path", NULL, NULL }; + size_t valuelen = 64*1024-1; + char *value = malloc(valuelen+1); + nghttp2_frame *frame = malloc(sizeof(nghttp2_frame)); + nghttp2_nv *nva; + ssize_t nvlen; + + memset(value, '0', valuelen); + value[valuelen] = '\0'; + nv[1] = value; + + memset(&callbacks, 0, sizeof(nghttp2_session_callbacks)); + callbacks.send_callback = null_send_callback; + + nghttp2_session_client_new(&session, &callbacks, NULL); + nvlen = nghttp2_nv_array_from_cstr(&nva, nv); + + nghttp2_frame_headers_init(&frame->headers, NGHTTP2_FLAG_END_HEADERS, -1, + NGHTTP2_PRI_DEFAULT, nva, nvlen); + + nghttp2_session_add_frame(session, NGHTTP2_CAT_CTRL, frame, NULL); + CU_ASSERT(0 == nghttp2_session_send(session)); + + CU_ASSERT(session->goaway_flags & + (NGHTTP2_GOAWAY_SEND | NGHTTP2_GOAWAY_FAIL_ON_SEND)); + + free(value); + nghttp2_session_del(session); +} + void test_nghttp2_session_send_priority(void) { nghttp2_session *session; diff --git a/tests/nghttp2_session_test.h b/tests/nghttp2_session_test.h index a71ba9f8..a21acca5 100644 --- a/tests/nghttp2_session_test.h +++ b/tests/nghttp2_session_test.h @@ -43,6 +43,7 @@ void test_nghttp2_session_on_window_update_received(void); void test_nghttp2_session_on_data_received(void); void test_nghttp2_session_send_headers_start_stream(void); void test_nghttp2_session_send_headers_reply(void); +void test_nghttp2_session_send_headers_header_comp_error(void); void test_nghttp2_session_send_priority(void); void test_nghttp2_session_send_rst_stream(void); void test_nghttp2_session_is_my_stream_id(void);