Skip to content

Commit fc56fb1

Browse files
yawkatsdelamo
andauthored
Do not log HTTP/2 ping from server (#11664)
Also add test case that the ping is properly responded to (netty does this for us). Fixes #10376 Co-authored-by: Sergio del Amo <[email protected]>
1 parent 42ddd49 commit fc56fb1

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

http-client/src/main/java/io/micronaut/http/client/netty/ConnectionManager.java

+2-1
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,7 @@
6868
import io.netty.handler.codec.http2.Http2HeadersFrame;
6969
import io.netty.handler.codec.http2.Http2MultiplexActiveStreamsException;
7070
import io.netty.handler.codec.http2.Http2MultiplexHandler;
71+
import io.netty.handler.codec.http2.Http2PingFrame;
7172
import io.netty.handler.codec.http2.Http2SettingsAckFrame;
7273
import io.netty.handler.codec.http2.Http2SettingsFrame;
7374
import io.netty.handler.codec.http2.Http2StreamChannel;
@@ -839,7 +840,7 @@ public void handlerAdded(ChannelHandlerContext ctx) throws Exception {
839840

840841
@Override
841842
public void channelRead(@NonNull ChannelHandlerContext ctx, @NonNull Object msg) throws Exception {
842-
if (msg instanceof Http2SettingsAckFrame) {
843+
if (msg instanceof Http2SettingsAckFrame || msg instanceof Http2PingFrame) {
843844
// this is fine
844845
return;
845846
}

http-client/src/test/groovy/io/micronaut/http/client/netty/ConnectionManagerSpec.groovy

+33
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ import io.netty.handler.codec.http2.DefaultHttp2DataFrame
5050
import io.netty.handler.codec.http2.DefaultHttp2GoAwayFrame
5151
import io.netty.handler.codec.http2.DefaultHttp2Headers
5252
import io.netty.handler.codec.http2.DefaultHttp2HeadersFrame
53+
import io.netty.handler.codec.http2.DefaultHttp2PingFrame
5354
import io.netty.handler.codec.http2.Http2Error
5455
import io.netty.handler.codec.http2.Http2FrameCodec
5556
import io.netty.handler.codec.http2.Http2FrameCodecBuilder
@@ -1245,6 +1246,38 @@ class ConnectionManagerSpec extends Specification {
12451246
'micronaut.http.client.http2.ping-interval-idle' | true
12461247
}
12471248

1249+
def 'http2 server ping'() {
1250+
given:
1251+
def ctx = ApplicationContext.run([
1252+
'micronaut.http.client.ssl.insecure-trust-all-certificates': true,
1253+
'spec.name': ConnectionManagerSpec.simpleName,
1254+
])
1255+
def client = ctx.getBean(DefaultHttpClient)
1256+
1257+
def conn = new EmbeddedTestConnectionHttp2()
1258+
conn.setupHttp2Tls()
1259+
patch(client, conn)
1260+
1261+
def future = conn.testExchangeRequest(client)
1262+
conn.exchangeSettings()
1263+
conn.testExchangeResponse(future)
1264+
1265+
assertPoolConnections(client, 1)
1266+
1267+
conn.serverChannel.writeAndFlush(new DefaultHttp2PingFrame(123))
1268+
conn.advance()
1269+
1270+
expect:
1271+
def pong = conn.serverChannel.readInbound()
1272+
pong instanceof Http2PingFrame
1273+
pong.ack
1274+
pong.content == 123
1275+
1276+
cleanup:
1277+
client.close()
1278+
ctx.close()
1279+
}
1280+
12481281
void assertPoolConnections(DefaultHttpClient client, int count) {
12491282
assert client.connectionManager.getChannels().size() == count
12501283
client.connectionManager.getChannels().forEach { assert it.isActive() }

0 commit comments

Comments
 (0)