Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -464,9 +464,14 @@ private void configure(Map<Integer, Integer> settings, boolean local)
if (LOG.isDebugEnabled())
LOG.debug("Updating {} max header list size to {} for {}", local ? "decoder" : "encoder", value, this);
if (local)
{
parser.getHpackDecoder().setMaxHeaderListSize(value);
}
else
generator.getHpackEncoder().setMaxHeaderListSize(value);
{
HpackEncoder hpackEncoder = generator.getHpackEncoder();
hpackEncoder.setMaxHeaderListSize(Math.min(value, hpackEncoder.getMaxHeaderListSize()));
}
}
case SettingsFrame.ENABLE_CONNECT_PROTOCOL ->
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public int getMaxHeaderListSize()

public void setMaxHeaderListSize(int maxHeaderListSize)
{
_maxHeaderListSize = maxHeaderListSize;
_maxHeaderListSize = maxHeaderListSize > 0 ? maxHeaderListSize : HpackContext.DEFAULT_MAX_HEADER_LIST_SIZE;
}

public HpackContext getHpackContext()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1315,6 +1315,7 @@ public boolean handle(Request request, Response response, Callback callback)
}, httpConfig);
connector.getBean(AbstractHTTP2ServerConnectionFactory.class).setMaxFrameSize(17 * 1024);
http2Client.setMaxFrameSize(18 * 1024);
http2Client.setMaxRequestHeadersSize(2 * maxHeadersSize);

// Wait for the SETTINGS frame to be exchanged.
CountDownLatch settingsLatch = new CountDownLatch(1);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -446,6 +446,42 @@ public void onGoAway(Session session, GoAwayFrame frame)
assertTrue(goAwayLatch.await(5, TimeUnit.SECONDS));
}

@Test
public void testMaxHeaderListSizeCappedByClient() throws Exception
{
int maxHeadersSize = 2 * 1024;
CountDownLatch goAwayLatch = new CountDownLatch(1);
start(new ServerSessionListener()
{
@Override
public Map<Integer, Integer> onPreface(Session session)
{
return Map.of(SettingsFrame.MAX_HEADER_LIST_SIZE, maxHeadersSize);
}

@Override
public void onGoAway(Session session, GoAwayFrame frame)
{
goAwayLatch.countDown();
}
});
http2Client.setMaxRequestHeadersSize(maxHeadersSize / 2);

Session clientSession = newClientSession(new Session.Listener() {});
HttpFields requestHeaders = HttpFields.build()
.put("X-Large", "x".repeat(maxHeadersSize - 256)); // 256 bytes to account for the other headers
MetaData.Request request = newRequest("GET", requestHeaders);
HeadersFrame frame = new HeadersFrame(request, null, true);

Throwable failure = assertThrows(ExecutionException.class,
() -> clientSession.newStream(frame, new Stream.Listener() {}).get(5, TimeUnit.SECONDS))
.getCause();
// The HPACK context is compromised trying to encode the large header.
assertThat(failure, Matchers.instanceOf(HpackException.SessionException.class));

assertTrue(goAwayLatch.await(5, TimeUnit.SECONDS));
}

@Test
public void testMaxHeaderListSizeExceededByServer() throws Exception
{
Expand Down
Loading