@@ -1142,6 +1142,71 @@ public void run() throws Http2Exception { |
1142 | 1142 | } |
1143 | 1143 | } |
1144 | 1144 |
|
| 1145 | + @Test |
| 1146 | + public void serverShouldNotEnforceClientAdvertisedMaxHeaderListSize() throws Exception { |
| 1147 | + // Verifies that SETTINGS_MAX_HEADER_LIST_SIZE sent by a client is treated as advisory |
| 1148 | + // (per RFC 9113 §6.5.2) and does not prevent the server from encoding response headers. |
| 1149 | + final CountDownLatch clientSettingsAckLatch = new CountDownLatch(2); |
| 1150 | + final CountDownLatch responseLatch = new CountDownLatch(1); |
| 1151 | + final AtomicReference<Throwable> serverWriteError = new AtomicReference<Throwable>(); |
| 1152 | + |
| 1153 | + doAnswer(new Answer<Void>() { |
| 1154 | + @Override |
| 1155 | + public Void answer(InvocationOnMock invocationOnMock) throws Throwable { |
| 1156 | + final ChannelHandlerContext sCtx = serverCtx(); |
| 1157 | + final int streamId = (Integer) invocationOnMock.getArgument(1); |
| 1158 | + Http2Headers responseHeaders = new DefaultHttp2Headers().status("200"); |
| 1159 | + http2Server.encoder().writeHeaders(sCtx, streamId, responseHeaders, 0, true, sCtx.newPromise()) |
| 1160 | + .addListener(future -> { |
| 1161 | + serverWriteError.set(future.cause()); |
| 1162 | + responseLatch.countDown(); |
| 1163 | + }); |
| 1164 | + http2Server.flush(sCtx); |
| 1165 | + return null; |
| 1166 | + } |
| 1167 | + }).when(serverListener).onHeadersRead(any(ChannelHandlerContext.class), anyInt(), any(Http2Headers.class), |
| 1168 | + anyInt(), anyShort(), anyBoolean(), anyInt(), anyBoolean()); |
| 1169 | + |
| 1170 | + doAnswer(new Answer<Void>() { |
| 1171 | + @Override |
| 1172 | + public Void answer(InvocationOnMock invocationOnMock) throws Throwable { |
| 1173 | + clientSettingsAckLatch.countDown(); |
| 1174 | + return null; |
| 1175 | + } |
| 1176 | + }).when(clientListener).onSettingsAckRead(any(ChannelHandlerContext.class)); |
| 1177 | + |
| 1178 | + bootstrapEnv(0, 1, 2, 0); |
| 1179 | + |
| 1180 | + // Client advertises a tiny MAX_HEADER_LIST_SIZE (2 bytes) to the server. |
| 1181 | + runInChannel(clientChannel, new Http2Runnable() { |
| 1182 | + @Override |
| 1183 | + public void run() throws Http2Exception { |
| 1184 | + http2Client.encoder().writeSettings(ctx(), |
| 1185 | + new Http2Settings().maxHeaderListSize(2), |
| 1186 | + newPromise()); |
| 1187 | + http2Client.flush(ctx()); |
| 1188 | + } |
| 1189 | + }); |
| 1190 | + |
| 1191 | + // Wait for the server to acknowledge both the initial settings and our custom settings. |
| 1192 | + assertTrue(clientSettingsAckLatch.await(DEFAULT_AWAIT_TIMEOUT_SECONDS, SECONDS)); |
| 1193 | + |
| 1194 | + // Send a request; the server will attempt to respond with headers far exceeding 2 bytes. |
| 1195 | + final short weight = 16; |
| 1196 | + runInChannel(clientChannel, new Http2Runnable() { |
| 1197 | + @Override |
| 1198 | + public void run() throws Http2Exception { |
| 1199 | + http2Client.encoder().writeHeaders(ctx(), 3, dummyHeaders(), 0, weight, false, 0, true, |
| 1200 | + newPromise()); |
| 1201 | + http2Client.flush(ctx()); |
| 1202 | + } |
| 1203 | + }); |
| 1204 | + |
| 1205 | + assertTrue(responseLatch.await(DEFAULT_AWAIT_TIMEOUT_SECONDS, SECONDS)); |
| 1206 | + assertNull(serverWriteError.get(), |
| 1207 | + "Server must succeed writing response headers regardless of client's SETTINGS_MAX_HEADER_LIST_SIZE"); |
| 1208 | + } |
| 1209 | + |
1145 | 1210 | private void bootstrapEnv(int dataCountDown, int settingsAckCount, |
1146 | 1211 | int requestCountDown, int trailersCountDown) throws Exception { |
1147 | 1212 | bootstrapEnv(dataCountDown, settingsAckCount, requestCountDown, trailersCountDown, -1, -1); |
|