diff --git a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameWriter.java b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameWriter.java index 196cbabb09..dc84c91042 100644 --- a/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameWriter.java +++ b/codec-http2/src/main/java/io/netty/handler/codec/http2/DefaultHttp2FrameWriter.java @@ -274,7 +274,7 @@ public class DefaultHttp2FrameWriter implements Http2FrameWriter, Http2FrameSize int streamDependency, short weight, boolean exclusive, ChannelPromise promise) { try { verifyStreamId(streamId, STREAM_ID); - verifyStreamId(streamDependency, STREAM_DEPENDENCY); + verifyStreamOrConnectionId(streamDependency, STREAM_DEPENDENCY); verifyWeight(weight); ByteBuf buf = ctx.alloc().buffer(PRIORITY_FRAME_LENGTH); @@ -602,11 +602,11 @@ public class DefaultHttp2FrameWriter implements Http2FrameWriter, Http2FrameSize } private static void verifyStreamId(int streamId, String argumentName) { - checkPositive(streamId, "streamId"); + checkPositive(streamId, argumentName); } private static void verifyStreamOrConnectionId(int streamId, String argumentName) { - checkPositiveOrZero(streamId, "streamId"); + checkPositiveOrZero(streamId, argumentName); } private static void verifyWeight(short weight) { diff --git a/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2FrameWriterTest.java b/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2FrameWriterTest.java index af1a9baa8f..ac634caada 100644 --- a/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2FrameWriterTest.java +++ b/codec-http2/src/test/java/io/netty/handler/codec/http2/DefaultHttp2FrameWriterTest.java @@ -277,6 +277,38 @@ public class DefaultHttp2FrameWriterTest { assertEquals(expectedOutbound, outbound); } + @Test + public void writePriority() { + frameWriter.writePriority( + ctx, /* streamId= */ 1, /* dependencyId= */ 2, /* weight= */ (short) 256, /* exclusive= */ true, promise); + + expectedOutbound = Unpooled.copiedBuffer(new byte[] { + (byte) 0x00, (byte) 0x00, (byte) 0x05, // payload length = 5 + (byte) 0x02, // payload type = 2 + (byte) 0x00, // flags = 0x00 + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, // stream id = 1 + (byte) 0x80, (byte) 0x00, (byte) 0x00, (byte) 0x02, // dependency id = 2 | exclusive = 1 << 63 + (byte) 0xFF, // weight = 255 (implicit +1) + }); + assertEquals(expectedOutbound, outbound); + } + + @Test + public void writePriorityDefaults() { + frameWriter.writePriority( + ctx, /* streamId= */ 1, /* dependencyId= */ 0, /* weight= */ (short) 16, /* exclusive= */ false, promise); + + expectedOutbound = Unpooled.copiedBuffer(new byte[] { + (byte) 0x00, (byte) 0x00, (byte) 0x05, // payload length = 5 + (byte) 0x02, // payload type = 2 + (byte) 0x00, // flags = 0x00 + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x01, // stream id = 1 + (byte) 0x00, (byte) 0x00, (byte) 0x00, (byte) 0x00, // dependency id = 0 | exclusive = 0 << 63 + (byte) 0x0F, // weight = 15 (implicit +1) + }); + assertEquals(expectedOutbound, outbound); + } + private byte[] headerPayload(int streamId, Http2Headers headers, byte padding) throws Http2Exception, IOException { if (padding == 0) { return headerPayload(streamId, headers);