List of usage examples for io.netty.handler.codec.http2 DefaultHttp2FrameReader readFrame
@Override public void readFrame(ChannelHandlerContext ctx, ByteBuf input, Http2FrameListener listener) throws Http2Exception
From source file:com.linecorp.armeria.client.Http2ClientSettingsTest.java
License:Apache License
@Test public void maxFrameSize() throws Exception { try (ServerSocket ss = new ServerSocket(0)) { final int port = ss.getLocalPort(); final ClientFactory clientFactory = new ClientFactoryBuilder().useHttp2Preface(true) .http2MaxFrameSize(DEFAULT_MAX_FRAME_SIZE * 2) // == 16384 * 2 .build();// w w w.ja v a 2 s .c o m final HttpClient client = HttpClient.of(clientFactory, "http://127.0.0.1:" + port); final CompletableFuture<AggregatedHttpMessage> future = client.get("/").aggregate(); try (Socket s = ss.accept()) { final InputStream in = s.getInputStream(); final BufferedOutputStream bos = new BufferedOutputStream(s.getOutputStream()); readBytes(in, connectionPrefaceBuf().capacity()); // Read the connection preface and discard it. // Read a SETTINGS frame and validate it. assertSettingsFrameOfMaxFrameSize(in); sendEmptySettingsAndAckFrame(bos); readBytes(in, 9); // Read a SETTINGS_ACK frame and discard it. readHeadersFrame(in); // Read a HEADERS frame and discard it. sendHeaderFrame(bos); //////////////////////////////////////// // Transmission of data gets started. // //////////////////////////////////////// // Send a DATA frame that indicates sending data as much as 0x8000 for stream id 03. bos.write(new byte[] { 0x00, (byte) 0x80, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 }); bos.write(EMPTY_DATA); bos.write(EMPTY_DATA); bos.flush(); readBytes(in, 13); // Read a WINDOW_UPDATE frame for connection and discard it. readBytes(in, 13); // Read a WINDOW_UPDATE frame for stream id 03 and discard it. // Send a DATA frame that exceed MAX_FRAME_SIZE by 1. bos.write(new byte[] { 0x00, (byte) 0x80, 0x01, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03 }); bos.flush(); // Triggers the client to send a GOAWAY frame for the connection. // The client send a GOAWAY frame and the server read it. final ByteBuf buffer = readGoAwayFrame(in); final DefaultHttp2FrameReader frameReader = new DefaultHttp2FrameReader(); final CountDownLatch latch = new CountDownLatch(1); frameReader.readFrame(null, buffer, new Http2EventAdapter() { @Override public void onGoAwayRead(ChannelHandlerContext ctx, int lastStreamId, long errorCode, ByteBuf debugData) throws Http2Exception { assertThat(lastStreamId).isZero(); // 0: connection error assertThat(errorCode).isEqualTo(Http2Error.FRAME_SIZE_ERROR.code()); latch.countDown(); } }); latch.await(); buffer.release(); } } }