Skip to content

Commit

Permalink
HTTPCORE-727: Protocol handlers fail to update input metrics when rec…
Browse files Browse the repository at this point in the history
…eive input data from a TLS encrypted I/O session
  • Loading branch information
ok2c committed Nov 2, 2022
1 parent 62c3bd3 commit 350bd4f
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -115,13 +115,16 @@ public RawFrame read(final ByteBuffer src, final ReadableByteChannel channel) th
buffer.clear();
}
final int remaining = buffer.remaining();
if (remaining >= src.remaining()) {
final int n = src.remaining();
if (remaining >= n) {
buffer.put(src);
metrics.incrementBytesTransferred(n);
} else {
final int limit = src.limit();
src.limit(remaining);
buffer.put(src);
src.limit(limit);
metrics.incrementBytesTransferred(remaining);
}
buffer.flip();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,22 @@ public void testReadWriteFrame() throws Exception {

Assertions.assertEquals(1, inBuffer.getMetrics().getFramesTransferred());
Assertions.assertEquals(bytes.length, inBuffer.getMetrics().getBytesTransferred());

final RawFrame frame3 = inBuffer.read(ByteBuffer.wrap(bytes), readableChannel);
Assertions.assertEquals(FrameType.DATA.getValue(), frame3.getType());
Assertions.assertEquals(0, frame3.getFlags());
Assertions.assertEquals(1L, frame3.getStreamId());
final ByteBuffer payload3 = frame3.getPayloadContent();
Assertions.assertNotNull(payload3);
Assertions.assertEquals(5, payload3.remaining());
Assertions.assertEquals(1, payload3.get());
Assertions.assertEquals(2, payload3.get());
Assertions.assertEquals(3, payload3.get());
Assertions.assertEquals(4, payload3.get());
Assertions.assertEquals(5, payload3.get());

Assertions.assertEquals(2, inBuffer.getMetrics().getFramesTransferred());
Assertions.assertEquals(bytes.length * 2, inBuffer.getMetrics().getBytesTransferred());
}

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,9 @@ IncomingMessage parseMessageHead(final boolean endOfStream) throws IOException,

public final void onInput(final ByteBuffer src) throws HttpException, IOException {
if (src != null) {
final int n = src.remaining();
inbuf.put(src);
inTransportMetrics.incrementBytesTransferred(n);
}

if (connState.compareTo(ConnectionState.GRACEFUL_SHUTDOWN) >= 0 && inbuf.hasData() && inputIdle()) {
Expand Down

0 comments on commit 350bd4f

Please sign in to comment.