@Override public HttpHeaders trailingHeaders() { return ((LastHttpContent) content).trailingHeaders(); }
@Override public HttpHeaders trailingHeaders() { if (content instanceof LastHttpContent) { return ((LastHttpContent) content).trailingHeaders(); } else { return EmptyHttpHeaders.INSTANCE; } }
protected void captureTrailingHeaders(LastHttpContent lastContent) { trailingHeaders = lastContent.trailingHeaders(); // technically, the Content-Encoding header can be in a trailing header, although this is excruciatingly uncommon if (trailingHeaders != null) { String trailingContentEncoding = trailingHeaders.get(HttpHeaders.Names.CONTENT_ENCODING); if (trailingContentEncoding != null) { contentEncoding = trailingContentEncoding; } } }
@Override protected void aggregate(FullHttpMessage aggregated, HttpContent content) throws Exception { if (content instanceof LastHttpContent) { // Merge trailing headers into the message. ((AggregatedFullHttpMessage) aggregated).setTrailingHeaders(((LastHttpContent) content).trailingHeaders()); } }
protected void captureTrailingHeaders(LastHttpContent lastHttpContent) { HttpHeaders headers = lastHttpContent.trailingHeaders(); captureHeaders(headers); }
@Override public HttpResponse clientToProxyRequest(HttpObject httpObject) { if (httpObject instanceof HttpRequest) { this.httpRequest = (HttpRequest) httpObject; } if (httpObject instanceof HttpContent) { HttpContent httpContent = (HttpContent) httpObject; storeRequestContent(httpContent); if (httpContent instanceof LastHttpContent) { LastHttpContent lastHttpContent = (LastHttpContent) httpContent; trailingHeaders = lastHttpContent .trailingHeaders(); } } return null; }
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 LastHttpContent copy() { LastHttpContent content = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER); content.trailingHeaders().set(trailingHeaders()); return content; }
@Override public LastHttpContent replace(ByteBuf content) { final LastHttpContent dup = new DefaultLastHttpContent(content); dup.trailingHeaders().setAll(trailingHeaders()); return dup; }
response.content().writeBytes(((HttpContent) msg).content()); if (msg instanceof LastHttpContent) { response.trailingHeaders().add(((LastHttpContent) msg).trailingHeaders()); try { handshakeComplete(ctx, response);
private LastHttpContent convertTrailingHeaders(int streamId, HttpHeaders headers) throws Http2Exception { final LastHttpContent lastContent; if (headers.isEmpty()) { lastContent = LastHttpContent.EMPTY_LAST_CONTENT; } else { lastContent = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER, false); convert(streamId, headers, lastContent.trailingHeaders(), true, false); } return lastContent; }
private void decodeContent(HttpContent c, List<Object> out) { ByteBuf content = c.content(); decode(content, out); if (c instanceof LastHttpContent) { finishDecode(out); LastHttpContent last = (LastHttpContent) c; // Generate an additional chunk if the decoder produced // the last product on closure, HttpHeaders headers = last.trailingHeaders(); if (headers.isEmpty()) { out.add(LastHttpContent.EMPTY_LAST_CONTENT); } else { out.add(new ComposedLastHttpContent(headers)); } } }
private void encodeChunkedContent(ChannelHandlerContext ctx, Object msg, long contentLength, List<Object> out) { if (contentLength > 0) { String lengthHex = Long.toHexString(contentLength); ByteBuf buf = ctx.alloc().buffer(lengthHex.length() + 2); buf.writeCharSequence(lengthHex, CharsetUtil.US_ASCII); ByteBufUtil.writeShortBE(buf, CRLF_SHORT); out.add(buf); out.add(encodeAndRetain(msg)); out.add(CRLF_BUF.duplicate()); } if (msg instanceof LastHttpContent) { HttpHeaders headers = ((LastHttpContent) msg).trailingHeaders(); if (headers.isEmpty()) { out.add(ZERO_CRLF_CRLF_BUF.duplicate()); } else { ByteBuf buf = ctx.alloc().buffer((int) trailersEncodedSizeAccumulator); ByteBufUtil.writeMediumBE(buf, ZERO_CRLF_MEDIUM); encodeHeaders(headers, buf); ByteBufUtil.writeShortBE(buf, CRLF_SHORT); trailersEncodedSizeAccumulator = TRAILERS_WEIGHT_NEW * padSizeForAccumulation(buf.readableBytes()) + TRAILERS_WEIGHT_HISTORICAL * trailersEncodedSizeAccumulator; out.add(buf); } } else if (contentLength == 0) { // Need to produce some output otherwise an // IllegalStateException will be thrown out.add(encodeAndRetain(msg)); } }
private boolean encodeContent(HttpContent c, List<Object> out) { ByteBuf content = c.content(); encode(content, out); if (c instanceof LastHttpContent) { finishEncode(out); LastHttpContent last = (LastHttpContent) c; // Generate an additional chunk if the decoder produced // the last product on closure, HttpHeaders headers = last.trailingHeaders(); if (headers.isEmpty()) { out.add(LastHttpContent.EMPTY_LAST_CONTENT); } else { out.add(new ComposedLastHttpContent(headers)); } return true; } return false; }
private void handleReadHttpContent(ChannelHandlerContext ctx, HttpContent content) { if (!ignoreBodyRead) { if (content instanceof LastHttpContent) { if (content.content().readableBytes() > 0 || !((LastHttpContent) content).trailingHeaders().isEmpty()) { // It has data or trailing headers, send them ctx.fireChannelRead(content); } else { ReferenceCountUtil.release(content); } removeHandlerIfActive(ctx, ctx.name() + "-body-publisher"); currentlyStreamedMessage = null; consumedInMessage(ctx); } else { ctx.fireChannelRead(content); } } else { ReferenceCountUtil.release(content); if (content instanceof LastHttpContent) { ignoreBodyRead = false; if (currentlyStreamedMessage != null) { removeHandlerIfActive(ctx, ctx.name() + "-body-publisher"); } currentlyStreamedMessage = null; } } }
char firstChar = line.charAt(0); if (lastHeader != null && (firstChar == ' ' || firstChar == '\t')) { List<String> current = trailer.trailingHeaders().getAll(lastHeader); if (!current.isEmpty()) { int lastPos = current.size() - 1; !HttpHeaderNames.TRANSFER_ENCODING.contentEqualsIgnoreCase(headerName) && !HttpHeaderNames.TRAILER.contentEqualsIgnoreCase(headerName)) { trailer.trailingHeaders().add(headerName, value);
if (chunk instanceof LastHttpContent) { LastHttpContent trailer = (LastHttpContent) chunk; HttpHeaders trailers = trailer.trailingHeaders(); if (trailers.isEmpty()) { spdyDataFrame.setLast(true);
private void handleChunk(HttpContent chunk, final Channel channel, final NettyResponseFuture<?> future, AsyncHandler<?> handler) throws Exception { boolean abort = false; boolean last = chunk instanceof LastHttpContent; // Netty 4: the last chunk is not empty if (last) { LastHttpContent lastChunk = (LastHttpContent) chunk; HttpHeaders trailingHeaders = lastChunk.trailingHeaders(); if (!trailingHeaders.isEmpty()) { abort = handler.onTrailingHeadersReceived(trailingHeaders) == State.ABORT; } } ByteBuf buf = chunk.content(); if (!abort && !(handler instanceof StreamedAsyncHandler) && (buf.isReadable() || last)) { HttpResponseBodyPart bodyPart = config.getResponseBodyPartFactory().newResponseBodyPart(buf, last); abort = handler.onBodyPartReceived(bodyPart) == State.ABORT; } if (abort || last) { boolean close = abort || !future.isKeepAlive(); finishUpdate(future, channel, close); } }
if (headers.method() == null && status == null) { LastHttpContent last = new DefaultLastHttpContent(Unpooled.EMPTY_BUFFER, validateHeaders); HttpConversionUtil.addHttp2ToHttpHeaders(id, headers, last.trailingHeaders(), HttpVersion.HTTP_1_1, true, true); out.add(last);
private boolean endResponse(LastHttpContent trailer) { synchronized (conn) { if (conn.metrics != null) { HttpClientRequestBase req = request; Object reqMetric = req.metric(); if (req.exceptionOccurred != null) { conn.metrics.requestReset(reqMetric); } else { conn.metrics.responseEnd(reqMetric, response); } } trailers = new HeadersAdaptor(trailer.trailingHeaders()); if (queue.isEmpty()) { response.handleEnd(trailers); } responseEnded = true; conn.close |= !conn.options.isKeepAlive(); conn.doResume(); return requestEnded; } }