From 66baa7dc2560a22eb35b8eef88612792b887f1ce Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Wed, 26 Apr 2017 22:15:53 +0900 Subject: [PATCH] Estimate header block size after predicate function succeeds --- lib/nghttp2_session.c | 38 +++++++++++++++----------------------- 1 file changed, 15 insertions(+), 23 deletions(-) diff --git a/lib/nghttp2_session.c b/lib/nghttp2_session.c index 1c060f1b..ec8898fb 100644 --- a/lib/nghttp2_session.c +++ b/lib/nghttp2_session.c @@ -2068,14 +2068,6 @@ static int session_prep_frame(nghttp2_session *session, /* We don't call nghttp2_session_adjust_closed_stream() here, since we don't keep closed stream in client side */ - estimated_payloadlen = session_estimate_headers_payload( - session, frame->headers.nva, frame->headers.nvlen, - NGHTTP2_PRIORITY_SPECLEN); - - if (estimated_payloadlen > session->max_send_header_block_length) { - return NGHTTP2_ERR_FRAME_SIZE_ERROR; - } - rv = session_predicate_request_headers_send(session, item); if (rv != 0) { return rv; @@ -2087,14 +2079,6 @@ static int session_prep_frame(nghttp2_session *session, } else { nghttp2_stream *stream; - estimated_payloadlen = session_estimate_headers_payload( - session, frame->headers.nva, frame->headers.nvlen, - NGHTTP2_PRIORITY_SPECLEN); - - if (estimated_payloadlen > session->max_send_header_block_length) { - return NGHTTP2_ERR_FRAME_SIZE_ERROR; - } - stream = nghttp2_session_get_stream(session, frame->hd.stream_id); if (stream && stream->state == NGHTTP2_STREAM_RESERVED) { @@ -2121,6 +2105,14 @@ static int session_prep_frame(nghttp2_session *session, } } + estimated_payloadlen = session_estimate_headers_payload( + session, frame->headers.nva, frame->headers.nvlen, + NGHTTP2_PRIORITY_SPECLEN); + + if (estimated_payloadlen > session->max_send_header_block_length) { + return NGHTTP2_ERR_FRAME_SIZE_ERROR; + } + rv = nghttp2_frame_pack_headers(&session->aob.framebufs, &frame->headers, &session->hd_deflater); @@ -2190,13 +2182,6 @@ static int session_prep_frame(nghttp2_session *session, nghttp2_stream *stream; size_t estimated_payloadlen; - estimated_payloadlen = session_estimate_headers_payload( - session, frame->push_promise.nva, frame->push_promise.nvlen, 0); - - if (estimated_payloadlen > session->max_send_header_block_length) { - return NGHTTP2_ERR_FRAME_SIZE_ERROR; - } - /* stream could be NULL if associated stream was already closed. */ stream = nghttp2_session_get_stream(session, frame->hd.stream_id); @@ -2209,6 +2194,13 @@ static int session_prep_frame(nghttp2_session *session, assert(stream); + estimated_payloadlen = session_estimate_headers_payload( + session, frame->push_promise.nva, frame->push_promise.nvlen, 0); + + if (estimated_payloadlen > session->max_send_header_block_length) { + return NGHTTP2_ERR_FRAME_SIZE_ERROR; + } + rv = nghttp2_frame_pack_push_promise( &session->aob.framebufs, &frame->push_promise, &session->hd_deflater); if (rv != 0) {