Skip to content

Commit f36b8a4

Browse files
committed
Update the HTTP/2 overhead documentation - particularly code comments
1 parent 3e92d5a commit f36b8a4

4 files changed

Lines changed: 59 additions & 27 deletions

File tree

java/org/apache/coyote/http2/Http2AsyncUpgradeHandler.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,9 @@ void sendStreamReset(StreamStateMachine state, StreamException se) throws IOExce
131131
log.trace(sm.getString("upgradeHandler.rst.debug", connectionId, Integer.toString(se.getStreamId()),
132132
se.getError(), se.getMessage()));
133133
}
134+
135+
increaseOverheadCount(FrameType.RST, getProtocol().getOverheadResetFactor());
136+
134137
// Write a RST frame
135138
byte[] rstFrame = new byte[13];
136139
// Length

java/org/apache/coyote/http2/Http2UpgradeHandler.java

Lines changed: 47 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -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
}

webapps/docs/changelog.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -125,6 +125,12 @@
125125
integers. Note that the maximum permitted value of an HPACK decoded
126126
integer is <code>Integer.MAX_VALUE</code>. (markt)
127127
</fix>
128+
<fix>
129+
Update the HTTP/2 overhead documentation - particularly the code
130+
comments - to reflect the deprecation of the <code>PRIORITY</code> frame
131+
and clarify that a stream reset always triggers an overhead increase.
132+
(markt)
133+
</fix>
128134
</changelog>
129135
</subsection>
130136
<subsection name="Cluster">

webapps/docs/config/http2.xml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,9 @@
241241
<attribute name="overheadResetFactor" required="false">
242242
<p>The amount by which the overhead count (see
243243
<strong>overheadCountFactor</strong>) will be increased for each reset
244-
frame received. If not specified, a default value of <code>50</code> will
245-
be used. A value of less than zero will be treated as zero.</p>
244+
frame received or sent. If not specified, a default value of
245+
<code>50</code> will be used. A value of less than zero will be treated as
246+
zero.</p>
246247
</attribute>
247248

248249
<attribute name="overheadDataThreshold" required="false">

0 commit comments

Comments
 (0)