@@ -582,6 +582,8 @@ void sendStreamReset(StreamStateMachine state, StreamException se) throws IOExce
582582 se .getError (), se .getMessage ()));
583583 }
584584
585+ increaseOverheadCount (FrameType .RST , getProtocol ().getOverheadResetFactor ());
586+
585587 // Write a RST frame
586588 byte [] rstFrame = new byte [13 ];
587589 // Length
@@ -1411,39 +1413,59 @@ protected final String getConnectionId() {
14111413
14121414
14131415 void reduceOverheadCount (FrameType frameType ) {
1414- // A non-overhead frame reduces the overhead count by
1415- // Http2Protocol.DEFAULT_OVERHEAD_REDUCTION_FACTOR. A simple browser
1416- // request is likely to have one non-overhead frame (HEADERS) and one
1417- // overhead frame (REPRIORITISE). With the default settings the overhead
1418- // count will reduce by 10 for each simple request.
1419- // Requests and responses with bodies will create additional
1420- // non-overhead frames, further reducing the overhead count.
1416+ /*
1417+ * A non-overhead frame reduces the overhead count by {@code Http2Protocol.DEFAULT_OVERHEAD_REDUCTION_FACTOR}.
1418+ *
1419+ * A simple browser request is likely to have one non-overhead frame (HEADERS) that results in a response with
1420+ * one further non-overhead frame (DATA). With the default settings, the overhead count will reduce by 40 for
1421+ * each simple request.
1422+ *
1423+ * Requests and responses with bodies will create additional non-overhead frames, further reducing the overhead
1424+ * count.
1425+ */
14211426 updateOverheadCount (frameType , Http2Protocol .DEFAULT_OVERHEAD_REDUCTION_FACTOR );
14221427 }
14231428
14241429
14251430 @ Override
14261431 public void increaseOverheadCount (FrameType frameType ) {
1427- // An overhead frame increases the overhead count by
1428- // overheadCountFactor. By default, this means an overhead frame
1429- // increases the overhead count by 10. A simple browser request is
1430- // likely to have one non-overhead frame (HEADERS) and one overhead
1431- // frame (REPRIORITISE). With the default settings the overhead count
1432- // will reduce by 10 for each simple request.
1432+ /*
1433+ * An overhead frame (SETTINGS, PRIORITY, PING) increases the overhead count by overheadCountFactor. By default,
1434+ * this means an overhead frame increases the overhead count by 10.
1435+ *
1436+ * If the client ignores maxConcurrentStreams then any HEADERS frame received will also increase the overhead
1437+ * count by overheadCountFactor.
1438+ *
1439+ * A simple browser request should not trigger any overhead frames.
1440+ */
14331441 updateOverheadCount (frameType , getProtocol ().getOverheadCountFactor ());
14341442 }
14351443
14361444
1437- private void increaseOverheadCount (FrameType frameType , int increment ) {
1438- // Overhead frames that indicate inefficient (and potentially malicious)
1439- // use of small frames trigger an increase that is inversely
1440- // proportional to size. The default threshold for all three potential
1441- // areas for abuse (HEADERS, DATA, WINDOW_UPDATE) is 1024 bytes. Frames
1442- // with sizes smaller than this will trigger an increase of
1443- // threshold/size.
1444- // DATA and WINDOW_UPDATE take an average over the last two non-final
1445- // frames to allow for client buffering schemes that can result in some
1446- // small DATA payloads.
1445+ /**
1446+ * Used to increase the overhead for frames that don't use the {@code overheadCountFactor} ({@code CONTINUATION},
1447+ * {@code DATA}, {@code WINDOW_UPDATE} and {@code RESET}).
1448+ *
1449+ * @param frameType The frame type triggering the overhead increase
1450+ * @param increment The amount by which the overhead is increased
1451+ */
1452+ protected void increaseOverheadCount (FrameType frameType , int increment ) {
1453+ /*
1454+ * Three types of frame are susceptible to inefficient (and potentially malicious) use of small frames. These
1455+ * trigger an increase in overhead that is inversely proportional to size. The default threshold for all three
1456+ * potential areas for abuse (CONTINUATION, DATA, WINDOW_UPDATE) is 1024 bytes. Frames with sizes smaller than
1457+ * this will trigger an increase of threshold/size.
1458+ *
1459+ * The check for DATA and WINDOW_UPDATE frames takes an average over the last two frames to allow for client
1460+ * buffering schemes that can result in some small DATA payloads.
1461+ *
1462+ * The CONTINUATION and DATA frames checks are skipped for end of headers (CONTINUATION) and end of stream
1463+ * (DATA) as those frames may be small for legitimate reasons.
1464+ *
1465+ * RESET frames (received or sent) trigger an increase of overheadResetFactor.
1466+ *
1467+ * In all cases, the calling method determines the extent to which the overhead count is increased.
1468+ */
14471469 updateOverheadCount (frameType , increment );
14481470 }
14491471
@@ -1652,9 +1674,9 @@ public void headersContinue(int payloadSize, boolean endOfHeaders) {
16521674 if (payloadSize < overheadThreshold ) {
16531675 if (payloadSize == 0 ) {
16541676 // Avoid division by zero
1655- increaseOverheadCount (FrameType .HEADERS , overheadThreshold );
1677+ increaseOverheadCount (FrameType .CONTINUATION , overheadThreshold );
16561678 } else {
1657- increaseOverheadCount (FrameType .HEADERS , overheadThreshold / payloadSize );
1679+ increaseOverheadCount (FrameType .CONTINUATION , overheadThreshold / payloadSize );
16581680 }
16591681 }
16601682 }
0 commit comments