From 4f19e6b638b3b11e0c787a6fab27abce1b079cba Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Thu, 31 Oct 2019 15:56:24 +0100 Subject: [PATCH] Fixes #4251 - Http 2.0 clients cannot upgrade protocol in 9.4.22 release. Fixed HTTP2-Settings header parsing. Signed-off-by: Simone Bordet --- .../jetty/http2/parser/SettingsBodyParser.java | 11 ++++++++--- .../eclipse/jetty/http2/server/HTTP2CServerTest.java | 2 +- 2 files changed, 9 insertions(+), 4 deletions(-) diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/SettingsBodyParser.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/SettingsBodyParser.java index b58fa8a8b51..5ca509f1271 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/SettingsBodyParser.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/parser/SettingsBodyParser.java @@ -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; @@ -234,7 +239,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(); diff --git a/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2CServerTest.java b/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2CServerTest.java index 48552abebac..0dbfd503e0d 100644 --- a/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2CServerTest.java +++ b/jetty-http2/http2-server/src/test/java/org/eclipse/jetty/http2/server/HTTP2CServerTest.java @@ -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();