Refine search
context.write(new DefaultHttpResponse(nettyResponse.protocolVersion(), nettyResponse.status(), headers), context.voidPromise()); if (context.pipeline().get(SslHandler.class) == null && context.pipeline().get(SmartHttpContentCompressor.class).shouldSkip(headers)) { sendFileFuture = context.write(new DefaultFileRegion(raf.getChannel(), 0, getLength()), context.newProgressivePromise()); sendFileFuture = context.writeAndFlush(new HttpChunkedInput(new ChunkedFile(raf, 0, getLength(), LENGTH_8K)), context.newProgressivePromise()); } catch (IOException e) {
ctx.channel().attr(NettyRequest.NEED_FLUSH).set(false); ChannelPipeline pipeline = ctx.pipeline(); boolean ssl = pipeline.get(SslHandler.class) != null; HttpChunkedInput chunkedInput = new HttpChunkedInput( new ChunkedNioFile(channel, offset, count, bufferSize)); ctx.channel().eventLoop().execute(() -> { ctx.write(rsp, ctx.voidPromise());
ctx.writeAndFlush(response); JerseyChunkedInput jerseyChunkedInput = new JerseyChunkedInput(ctx.channel()); ctx.write(new HttpChunkedInput(jerseyChunkedInput)).addListener(FLUSH_FUTURE); } else { ctx.write(new HttpChunkedInput(jerseyChunkedInput)).addListener(FLUSH_FUTURE);
@Override public void write(HttpRequest<?> request, MutableHttpResponse<?> response, ChannelHandlerContext context) { if (response instanceof NettyMutableHttpResponse) { FullHttpResponse nettyResponse = ((NettyMutableHttpResponse) response).getNativeResponse(); // Write the request data context.write(new DefaultHttpResponse(nettyResponse.protocolVersion(), nettyResponse.status(), nettyResponse.headers()), context.voidPromise()); context.writeAndFlush(new HttpChunkedInput(new ChunkedStream(getInputStream()))); } else { throw new IllegalArgumentException("Unsupported response type. Not a Netty response: " + response); } } }
protected boolean writeResponse(ChannelHandlerContext ctx, FullHttpRequest request, ChunkedInput<ByteBuf> content, int length) { // Build the response object. HttpResponse response = new DefaultHttpResponse(HTTP_1_1, OK); return internalWriteResponse(ctx, request, response, length, () -> { HttpChunkedInput chunked = new HttpChunkedInput(content, LastHttpContent.EMPTY_LAST_CONTENT); ctx.write(response); return ctx.writeAndFlush(chunked); }); }
private ChannelFuture sendFile(ChannelHandlerContext ctx, FileChunk file) throws IOException { RandomAccessFile raf; try { raf = new RandomAccessFile(file.getFile(), "r"); } catch (FileNotFoundException fnfe) { return null; } ChannelFuture writeFuture; ChannelFuture lastContentFuture; if (ctx.pipeline().get(SslHandler.class) != null) { // Cannot use zero-copy with HTTPS. lastContentFuture = ctx.write(new HttpChunkedInput(new ChunkedFile(raf, file.startOffset(), file.length(), 8192))); } else { // No encryption - use zero-copy. final FileRegion region = new DefaultFileRegion(raf.getChannel(), file.startOffset(), file.length()); writeFuture = ctx.write(region); lastContentFuture = ctx.write(LastHttpContent.EMPTY_LAST_CONTENT); writeFuture.addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) { if (region.refCnt() > 0) { region.release(); } } }); } return lastContentFuture; }
new ChunkedWriter(ctx.channel(), true, ka) : new StreamWriter(ctx.channel(), true, ka); request = State.class.cast(ctx.attr(ATTACHMENT).get()).request; boolean isLast = HttpChunkedInput.class.cast(messageEvent).isEndOfInput(); Boolean ka = (Boolean) request.getAttribute(KEEP_ALIVE); new StreamWriter(ctx.channel(), isLast, ka); method = request.getMethod(); ByteBuf internalBuffer = HttpChunkedInput.class.cast(messageEvent).readChunk(ctx).content();
@Override public void operationComplete(ChannelFuture future) throws Exception { try { Channel channel = future.channel(); HttpRequest request = RequestAdapter.adapt(marshalledRequest); // Send request channel.writeAndFlush(request); // Send chunked content channel.writeAndFlush(new HttpChunkedInput(new ChunkedStream(marshalledRequest.getContent()))); } catch (Exception e) { responseHandler.onFailure(e); } } });
ctx.channel().attr(NettyRequest.NEED_FLUSH).set(false); ChannelPipeline pipeline = ctx.pipeline(); boolean ssl = pipeline.get(SslHandler.class) != null; HttpChunkedInput chunkedInput = new HttpChunkedInput( new ChunkedNioFile(channel, offset, count, bufferSize)); ctx.channel().eventLoop().execute(() -> { ctx.write(rsp, ctx.voidPromise());
private ChannelFuture writeStaticFile(ChannelHandlerContext ctx, String resourceFullPath) { InputStream inputStream = getClass().getResourceAsStream(resourceFullPath); if (inputStream == null) { return writeJsonResponse(ctx, NOT_FOUND, NOT_FOUND_RESPONSE); } DefaultHttpResponse resp = new DefaultHttpResponse(HTTP_1_1, OK); resp.headers().set(CONNECTION, isKeepAlive ? KEEP_ALIVE : CLOSE); resp.headers().set(CONTENT_TYPE, mimeTypesMap.getContentType(resourceFullPath)); HttpUtil.setTransferEncodingChunked(resp, true); ctx.write(resp); return ctx.writeAndFlush(new HttpChunkedInput(new ChunkedStream(inputStream))); }
private ChannelFuture sendFile(ChannelHandlerContext ctx, FileChunk file) throws IOException { RandomAccessFile raf; try { raf = new RandomAccessFile(file.getFile(), "r"); } catch (FileNotFoundException fnfe) { return null; } ChannelFuture writeFuture; ChannelFuture lastContentFuture; if (ctx.pipeline().get(SslHandler.class) != null) { // Cannot use zero-copy with HTTPS. lastContentFuture = ctx.write(new HttpChunkedInput(new ChunkedFile(raf, file.startOffset(), file.length(), 8192))); } else { // No encryption - use zero-copy. final FileRegion region = new DefaultFileRegion(raf.getChannel(), file.startOffset(), file.length()); writeFuture = ctx.write(region); lastContentFuture = ctx.write(LastHttpContent.EMPTY_LAST_CONTENT); writeFuture.addListener(new ChannelFutureListener() { public void operationComplete(ChannelFuture future) { if (region.refCnt() > 0) { region.release(); } } }); } return lastContentFuture; }
new ChunkedWriter(ctx.channel(), true, ka) : new StreamWriter(ctx.channel(), true, ka); request = State.class.cast(ctx.attr(ATTACHMENT).get()).request; boolean isLast = HttpChunkedInput.class.cast(messageEvent).isEndOfInput(); Boolean ka = (Boolean) request.getAttribute(KEEP_ALIVE); new StreamWriter(ctx.channel(), isLast, ka); method = request.getMethod(); ByteBuf internalBuffer = HttpChunkedInput.class.cast(messageEvent).readChunk(ctx).content();
ch.write(new HttpChunkedInput(jerseyChunkedInput)); } else { ch.write(jerseyChunkedInput);
ctx.write(response); if (ctx.pipeline().get(SslHandler.class) == null) { ctx.write(new DefaultFileRegion(raf.getChannel(), 0, fileLength), ctx.newProgressivePromise()); lastContentFuture = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); } else { sendFileFuture = ctx.writeAndFlush(new HttpChunkedInput(new ChunkedFile(raf, 128 * 1024)), ctx.newProgressivePromise());
try { spill = new RandomAccessFile(file.getFile(), "r"); if (ctx.pipeline().get(SslHandler.class) == null) { final FadvisedFileRegion filePart = new FadvisedFileRegion(spill, file.startOffset(), file.length(), manageOsCache, readaheadLength, readaheadPool, file.getFile().getAbsolutePath()); writeFuture = ctx.write(filePart); writeFuture.addListener(new FileCloseListener(filePart, requestUri, startTime, TajoPullServerService.this)); } else { manageOsCache, readaheadLength, readaheadPool, file.getFile().getAbsolutePath()); writeFuture = ctx.write(new HttpChunkedInput(chunk));
// Write the content. ChannelFuture sendFileFuture; ChannelFuture lastContentFuture; if (ctx.pipeline().get(SslHandler.class) == null) { sendFileFuture = ctx.write(new DefaultFileRegion(raf.getChannel(), 0, fileLength), ctx.newProgressivePromise()); // Write the end marker. lastContentFuture = ctx.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT); // <= last writeAndFlush } else { sendFileFuture = ctx.writeAndFlush(new HttpChunkedInput(new ChunkedFile(raf, 0, fileLength, 8192)), ctx.newProgressivePromise()); // <= last writeAndFlush // HttpChunkedInput will write the end marker (LastHttpContent) for us. lastContentFuture = sendFileFuture; }
ctx.write(httpResponse); if (ctx.pipeline().get(SslHandler.class) == null) { sendFileFuture = ctx.write( new DefaultFileRegion(raf.getChannel(), 0, fileLength), ctx.newProgressivePromise() sendFileFuture = ctx.writeAndFlush( new HttpChunkedInput( new ChunkedFile(raf, 0, fileLength, 8192) ),
try { spill = new RandomAccessFile(file.getFile(), "r"); if (ctx.pipeline().get(SslHandler.class) == null) { final FadvisedFileRegion filePart = new FadvisedFileRegion(spill, file.startOffset(), file.length(), manageOsCache, readaheadLength, readaheadPool, file.getFile().getAbsolutePath()); writeFuture = ctx.write(filePart); writeFuture.addListener(new FileCloseListener(filePart)); } else { manageOsCache, readaheadLength, readaheadPool, file.getFile().getAbsolutePath()); writeFuture = ctx.write(new HttpChunkedInput(chunk));