@@ -2438,16 +2438,23 @@ defmodule Mint.HTTP2 do
24382438 conn = put_in ( conn . headers_being_processed , nil )
24392439 callback . ( conn , responses , hbf , stream )
24402440 else
2441- new_size = acc_size + byte_size ( hbf_chunk )
2442- conn = assert_header_block_within_max_size ( conn , new_size )
2441+ if byte_size ( hbf_chunk ) == 0 do
2442+ # An empty fragment does not contribute header-block data. Keeping the
2443+ # existing accumulator avoids adding an unbounded number of empty
2444+ # iodata nodes when END_HEADERS is withheld.
2445+ { conn , responses }
2446+ else
2447+ new_size = acc_size + byte_size ( hbf_chunk )
2448+ conn = assert_header_block_within_max_size ( conn , new_size )
24432449
2444- conn =
2445- put_in (
2446- conn . headers_being_processed ,
2447- { stream_id , [ hbf_acc , hbf_chunk ] , callback , new_size }
2448- )
2450+ conn =
2451+ put_in (
2452+ conn . headers_being_processed ,
2453+ { stream_id , [ hbf_acc , hbf_chunk ] , callback , new_size }
2454+ )
24492455
2450- { conn , responses }
2456+ { conn , responses }
2457+ end
24512458 end
24522459 end
24532460
@@ -2461,8 +2468,9 @@ defmodule Mint.HTTP2 do
24612468 # CONTINUATION frames is buffered (in compressed form) until END_HEADERS
24622469 # arrives. A server can withhold END_HEADERS and stream CONTINUATION frames
24632470 # indefinitely, so the buffered size is bounded by the locally advertised
2464- # SETTINGS_MAX_HEADER_LIST_SIZE. The compressed accumulator is never larger
2465- # than the uncompressed header list it decodes to, so this never rejects a
2471+ # SETTINGS_MAX_HEADER_LIST_SIZE. Empty fragments are not retained in the
2472+ # accumulator. The compressed accumulator is never larger than the
2473+ # uncompressed header list it decodes to, so the size limit never rejects a
24662474 # header block that fits within the advertised limit.
24672475 defp assert_header_block_within_max_size ( conn , size ) do
24682476 case conn . client_settings . max_header_list_size do
0 commit comments