Merge pull request #4261 from eclipse/jetty-9.4.x-4251-broken_http2-settings_header

Fixes #4251 - Http 2.0 clients cannot upgrade protocol in 9.4.22 rele…
This commit is contained in:
Simone Bordet 2019-11-01 00:35:59 +03:00 committed by GitHub
commit cc92ad0b07
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 4 deletions

View File

@ -83,6 +83,11 @@ public class SettingsBodyParser extends BodyParser
@Override
public boolean parse(ByteBuffer buffer)
{
return parse(buffer, getStreamId(), getBodyLength());
}
private boolean parse(ByteBuffer buffer, int streamId, int bodyLength)
{
while (buffer.hasRemaining())
{
@ -91,9 +96,9 @@ public class SettingsBodyParser extends BodyParser
case PREPARE:
{
// SPEC: wrong streamId is treated as connection error.
if (getStreamId() != 0)
if (streamId != 0)
return connectionFailure(buffer, ErrorCode.PROTOCOL_ERROR.code, "invalid_settings_frame");
length = getBodyLength();
length = bodyLength;
settings = new HashMap<>();
state = State.SETTING_ID;
break;
@ -216,6 +221,13 @@ public class SettingsBodyParser extends BodyParser
return true;
}
/**
* <p>Parses the given buffer containing the whole body of a {@code SETTINGS} frame
* (without header bytes), typically from the {@code HTTP2-Settings} header.</p>
*
* @param buffer the buffer containing the body of {@code SETTINGS} frame
* @return the {@code SETTINGS} frame from the parsed body bytes
*/
public static SettingsFrame parseBody(final ByteBuffer buffer)
{
AtomicReference<SettingsFrame> frameRef = new AtomicReference<>();
@ -234,7 +246,7 @@ public class SettingsBodyParser extends BodyParser
}
});
if (buffer.hasRemaining())
parser.parse(buffer);
parser.parse(buffer, 0, buffer.remaining());
else
parser.emptyBody(buffer);
return frameRef.get();

View File

@ -125,7 +125,7 @@ public class HTTP2CServerTest extends AbstractServerTest
"Host: localhost\r\n" +
"Connection: something, else, upgrade, HTTP2-Settings\r\n" +
"Upgrade: h2c\r\n" +
"HTTP2-Settings: \r\n" +
"HTTP2-Settings: AAEAAEAAAAIAAAABAAMAAABkAAQBAAAAAAUAAEAA\r\n" +
"\r\n").getBytes(StandardCharsets.ISO_8859_1));
output.flush();