private void encodeLastContent(LastHttpContent last, List<Object> out) { boolean needFiller = !(last instanceof FullHttpMessage) && last.trailingHeaders().isEmpty(); if (last.content().isReadable() || needFiller) { out.add(new DefaultHttp2DataFrame(last.content().retain(), last.trailingHeaders().isEmpty())); } if (!last.trailingHeaders().isEmpty()) { Http2Headers headers = HttpConversionUtil.toHttp2Headers(last.trailingHeaders(), validateHeaders); out.add(new DefaultHttp2HeadersFrame(headers, true)); } }
case 1: assertTrue(obj instanceof LastHttpContent); ByteBuf content = ((LastHttpContent) obj).content(); assertEquals(!expectSSL, content.isDirect()); assertEquals(1, content.refCnt());
case 1: assertTrue(obj instanceof LastHttpContent); ByteBuf content = ((LastHttpContent) obj).content(); assertEquals(!expectSSL, content.isDirect()); assertEquals(1, content.refCnt());
private void encodeLastContent(LastHttpContent last, List<Object> out) { boolean needFiller = !(last instanceof FullHttpMessage) && last.trailingHeaders().isEmpty(); if (last.content().isReadable() || needFiller) { out.add(new DefaultHttp2DataFrame(last.content().retain(), last.trailingHeaders().isEmpty())); } if (!last.trailingHeaders().isEmpty()) { Http2Headers headers = HttpConversionUtil.toHttp2Headers(last.trailingHeaders(), validateHeaders); out.add(new DefaultHttp2HeadersFrame(headers, true)); } }
private void encodeLastContent(LastHttpContent last, List<Object> out) { boolean needFiller = !(last instanceof FullHttpMessage) && last.trailingHeaders().isEmpty(); if (last.content().isReadable() || needFiller) { out.add(new DefaultHttp2DataFrame(last.content().retain(), last.trailingHeaders().isEmpty())); } if (!last.trailingHeaders().isEmpty()) { Http2Headers headers = HttpConversionUtil.toHttp2Headers(last.trailingHeaders(), validateHeaders); out.add(new DefaultHttp2HeadersFrame(headers, true)); } }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { HttpProcessingState state = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get(); allowCompressionForThisRequest = false; if (state != null) { // We only want to allow compression if the endpoint being hit is *not* a ProxyRouterEndpoint, the response is full, and the response size // is greater than the threshold boolean isFull = msg instanceof HttpResponse && msg instanceof LastHttpContent; boolean endpointAllowed = endpointAllowsCompression(state.getEndpointForExecution()); boolean responseInfoAllowed = state.getResponseInfo() == null || !state.getResponseInfo().isPreventCompressedOutput(); if (isFull && endpointAllowed && responseInfoAllowed && ((LastHttpContent) msg).content().readableBytes() > responseSizeThresholdBytes) { allowCompressionForThisRequest = true; } } super.write(ctx, msg, promise); }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { // .请求头 if (msg instanceof HttpResponse) { HttpResponse response = (HttpResponse) msg; this.httpResponse = new RsfHttpResponseObject(response.protocolVersion(), response.status()); return; } // .请求数据(最后一个) if (msg instanceof LastHttpContent) { LastHttpContent http = (LastHttpContent) msg; ByteBuf content = http.content(); this.httpResponse.getHttpResponse().content().writeBytes(content); this.responseFuture.completed(this.httpResponse); return; } // 请求数据 if (msg instanceof HttpContent) { HttpContent http = (HttpContent) msg; ByteBuf content = http.content(); this.httpResponse.getHttpResponse().content().writeBytes(content); return; } // super.channelRead(ctx, msg); } @Override
@Test public void StreamingChannel_doStreamChunk_works_as_expected_when_last_chunk_already_sent_downstream_and_incoming_chunk_is_empty_last_chunk() { // given streamingChannelSpy.downstreamLastChunkSentHolder.heldObject = true; LastHttpContent contentChunkMock = mock(LastHttpContent.class); ByteBuf contentByteBufMock = mock(ByteBuf.class); doReturn(contentByteBufMock).when(contentChunkMock).content(); doReturn(0).when(contentByteBufMock).readableBytes(); ChannelFuture successFutureMock = mock(ChannelFuture.class); doReturn(successFutureMock).when(channelMock).newSucceededFuture(); // when ChannelFuture result = streamingChannelSpy.doStreamChunk(contentChunkMock); // then verify(channelMock, never()).writeAndFlush(any(Object.class)); verify(contentChunkMock).release(); verify(channelMock).newSucceededFuture(); assertThat(result).isSameAs(successFutureMock); }
accessLog.increaseContentLength(((LastHttpContent) msg).content().readableBytes()); ctx.write(msg, promise) .addListener(future -> {
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { HttpProcessingState state = ChannelAttributes.getHttpProcessingStateForChannel(ctx).get(); allowCompressionForThisRequest = false; if (state != null) { // We only want to allow compression if the endpoint being hit is *not* a ProxyRouterEndpoint, the response is full, and the response size // is greater than the threshold boolean isFull = msg instanceof HttpResponse && msg instanceof LastHttpContent; boolean endpointAllowed = endpointAllowsCompression(state.getEndpointForExecution()); boolean responseInfoAllowed = state.getResponseInfo() == null || !state.getResponseInfo().isPreventCompressedOutput(); if (isFull && endpointAllowed && responseInfoAllowed && ((LastHttpContent) msg).content().readableBytes() > responseSizeThresholdBytes) { allowCompressionForThisRequest = true; } } super.write(ctx, msg, promise); }
accessLog.increaseContentLength(((LastHttpContent) msg).content().readableBytes()); ctx.write(msg, promise) .addListener(future -> {
accessLog.increaseContentLength(((LastHttpContent) msg).content().readableBytes()); ctx.write(msg, promise) .addListener(future -> {
CONTENT_LENGTH, ((LastHttpContent) actualResponseObject).content().readableBytes() );
CONTENT_LENGTH, ((LastHttpContent) actualResponseObject).content().readableBytes() );
ByteBuf content = ((LastHttpContent) msg).content(); this.httpRequest.getNettyRequest().content().writeBytes(content); if (HttpMethod.POST.equals(this.httpRequest.getNettyRequest().method())) {
private ChannelFuture writeOutboundResponseHeaderAndBody(HttpOutboundRespListener outboundRespListener, HttpCarbonMessage outboundResponseMsg, LastHttpContent lastHttpContent) { CompositeByteBuf allContent = Unpooled.compositeBuffer(); for (HttpContent cachedHttpContent : contentList) { allContent.addComponent(true, cachedHttpContent.content()); } allContent.addComponent(true, lastHttpContent.content()); if (headRequest) { allContent.release(); allContent = Unpooled.compositeBuffer(); allContent.addComponent(true, new DefaultLastHttpContent().content()); } HttpResponse fullOutboundResponse = createFullHttpResponse(outboundResponseMsg, outboundRespListener.getRequestDataHolder() .getHttpVersion(), outboundRespListener.getServerName(), outboundRespListener.isKeepAlive(), allContent); ChannelFuture outboundChannelFuture = sourceContext.writeAndFlush(fullOutboundResponse); checkForResponseWriteStatus(inboundRequestMsg, outboundRespStatusFuture, outboundChannelFuture); return outboundChannelFuture; }