I'm attempting to send a file to the response and support encoding. The code is mostly copied from one of the examples in the Netty github.
ChannelFuture flushFuture;
if (context.pipeline().get(SslHandler.class) == null) {
// SSL not enabled - can use zero-copy file transfer.
context.write(new DefaultFileRegion(raf.getChannel(), 0, getLength()), context.newProgressivePromise());
flushFuture = context.writeAndFlush(LastHttpContent.EMPTY_LAST_CONTENT);
} else {
// SSL enabled - cannot use zero-copy file transfer.
try {
// HttpChunkedInput will write the end marker (LastHttpContent) for us.
flushFuture = context.writeAndFlush(new HttpChunkedInput(new ChunkedFile(raf, 0, getLength(), 8192)),
context.newProgressivePromise());
} catch (IOException e) {
throw new CustomizableResponseTypeException("Could not read file", e);
}
}
When the server is using SSL, all works well. When SSL is not being used, the zero-copy file transfer is being done and the encoding doesn't produce the correct output.
I've ready this blog post that seems to indicate what I'm trying to do could work, however I don't understand what part of the example code could cause it to work. Any tips or help will be appreciated.
Thanks!