@Override public ByteBuf content() { return content.content(); }
@Override public int getBodyLength() { int size = 0; for (final HttpContent chunk : bodyChunks) { size += chunk.content().readableBytes(); } return size; }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { State state = getOrCreateCurrentState(ctx.channel()); // Update the response body size with this chunk. if (msg instanceof HttpContent) { state.responseBodySize += ((HttpContent) msg).content().readableBytes(); } super.write(ctx, msg, promise); } }
@Override public byte[] getBody() { if (bodyChunks.size() == 0) { return null; } int size = 0; for (final HttpContent chunk : bodyChunks) { size += chunk.content().readableBytes(); } final byte[] body = new byte[size]; int offset = 0; for (final HttpContent chunk : bodyChunks) { final ByteBuf content = chunk.content(); final int len = content.readableBytes(); content.getBytes(content.readerIndex(), body, offset, len); offset += len; } return body; }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { RequestState state = ctx.channel().attr(ATTR_REQ_STATE).get(); if (msg instanceof HttpResponse) { state.response = (HttpResponse) msg; state.responseBodySize = 0; } if (msg instanceof HttpContent) { state.responseBodySize += ((HttpContent) msg).content().readableBytes(); } super.write(ctx, msg, promise); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { State state = null; // Reset the state as each new request comes in. if (msg instanceof HttpRequest) { state = createNewState(ctx.channel()); } // Update the request body size with this chunk. if (msg instanceof HttpContent) { if (state == null) { state = getOrCreateCurrentState(ctx.channel()); } state.requestBodySize += ((HttpContent) msg).content().readableBytes(); } super.channelRead(ctx, msg); }
/** * Adds the current {@link HttpContent} to the cumulation of data. * * @param ctx Channel context. * @param msg Current {@link HttpContent} message. */ private void cumulateContent(ChannelHandlerContext ctx, HttpContent msg) { cumulation = cumulator.cumulate(ctx.alloc(), cumulation, msg.content()); }
@Override public int getBodyLength() { int size = 0; for (final HttpContent chunk : bodyChunks) { size += chunk.content().readableBytes(); } return size; }
private void handleHttpMessage(HttpObject obj) { if (obj instanceof HttpResponse) { handleResponseBegin((HttpResponse) obj); } else if (obj instanceof HttpContent) { HttpContent chunk = (HttpContent) obj; if (chunk.content().isReadable()) { Buffer buff = Buffer.buffer(VertxHandler.safeBuffer(chunk.content(), chctx.alloc())); handleResponseChunk(buff); } if (chunk instanceof LastHttpContent) { handleResponseEnd((LastHttpContent) chunk); } } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { RequestState state = new RequestState(); state.request = (HttpRequest) msg; state.startTimeNs = System.nanoTime(); state.requestBodySize = 0; ctx.channel().attr(ATTR_REQ_STATE).set(state); } if (msg instanceof HttpContent) { RequestState state = ctx.channel().attr(ATTR_REQ_STATE).get(); if (state != null) { state.requestBodySize += ((HttpContent) msg).content().readableBytes(); } } super.channelRead(ctx, msg); }
private static Object encodeAndRetain(Object msg) { if (msg instanceof ByteBuf) { return ((ByteBuf) msg).retain(); } if (msg instanceof HttpContent) { return ((HttpContent) msg).content().retain(); } if (msg instanceof FileRegion) { return ((FileRegion) msg).retain(); } throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg)); }
private static long contentLength(Object msg) { if (msg instanceof HttpContent) { return ((HttpContent) msg).content().readableBytes(); } if (msg instanceof ByteBuf) { return ((ByteBuf) msg).readableBytes(); } if (msg instanceof FileRegion) { return ((FileRegion) msg).count(); } throw new IllegalStateException("unexpected message type: " + StringUtil.simpleClassName(msg)); }
public void write(final HttpContent chunk) { try { write(chunk.content()); gzos.flush(); } catch(IOException ioEx) { throw new ZuulException(ioEx, "Error Gzipping response content chunk", true); } finally { chunk.release(); } }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { State state = getOrCreateCurrentState(ctx.channel()); // Update the response body size with this chunk. if (msg instanceof HttpContent) { state.responseBodySize += ((HttpContent) msg).content().readableBytes(); } super.write(ctx, msg, promise); } }
private long getBytes(Object obj) { if (obj == null) return 0; if (obj instanceof Buffer) { return ((Buffer) obj).length(); } else if (obj instanceof ByteBuf) { return ((ByteBuf) obj).readableBytes(); } else if (obj instanceof HttpContent) { return ((HttpContent) obj).content().readableBytes(); } else if (obj instanceof WebSocketFrame) { return ((WebSocketFrame) obj).content().readableBytes(); } else if (obj instanceof FileRegion) { return ((FileRegion) obj).count(); } else if (obj instanceof ChunkedFile) { ChunkedFile file = (ChunkedFile) obj; return file.endOffset() - file.startOffset(); } else { return -1; } }
@Override public void write(ChannelHandlerContext ctx, Object msg, ChannelPromise promise) throws Exception { RequestState state = ctx.channel().attr(ATTR_REQ_STATE).get(); if (msg instanceof HttpResponse) { state.response = (HttpResponse) msg; state.responseBodySize = 0; } if (msg instanceof HttpContent) { state.responseBodySize += ((HttpContent) msg).content().readableBytes(); } super.write(ctx, msg, promise); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { State state = null; // Reset the state as each new request comes in. if (msg instanceof HttpRequest) { state = createNewState(ctx.channel()); } // Update the request body size with this chunk. if (msg instanceof HttpContent) { if (state == null) { state = getOrCreateCurrentState(ctx.channel()); } state.requestBodySize += ((HttpContent) msg).content().readableBytes(); } super.channelRead(ctx, msg); }
private void handleContent(Object msg) { HttpContent content = (HttpContent) msg; if (content.decoderResult() != DecoderResult.SUCCESS) { handleError(content); return; } Buffer buffer = Buffer.buffer(VertxHandler.safeBuffer(content.content(), chctx.alloc())); if (METRICS_ENABLED) { reportBytesRead(buffer); } requestInProgress.handleContent(buffer); //TODO chunk trailers if (content instanceof LastHttpContent) { handleEnd(); } }
@Override public void channelRead(ChannelHandlerContext ctx, Object msg) throws Exception { if (msg instanceof HttpRequest) { RequestState state = new RequestState(); state.request = (HttpRequest) msg; state.startTimeNs = System.nanoTime(); state.requestBodySize = 0; ctx.channel().attr(ATTR_REQ_STATE).set(state); } if (msg instanceof HttpContent) { RequestState state = ctx.channel().attr(ATTR_REQ_STATE).get(); if (state != null) { state.requestBodySize += ((HttpContent) msg).content().readableBytes(); } } super.channelRead(ctx, msg); }
public void write(final HttpContent chunk) { try { write(chunk.content()); gzos.flush(); } catch(IOException ioEx) { throw new ZuulException(ioEx, "Error Gzipping response content chunk", true); } finally { chunk.release(); } }