I wrote a netty 4.0.33 https file server that is suppose to send files as chucks. The File-Server-Example Shows when using https to handle the response like this:
// Write the initial line and the header.
channelHandlerContext.write(httpResponse);
// Write the content.
ChannelFuture sendFileFuture;
sendFileFuture = channelHandlerContext.writeAndFlush(
new HttpChunkedInput(new ChunkedFile(accessFile, 0, accessFile.length(), 8192)),
channelHandlerContext.newProgressivePromise()
);
My file I tested it with is only 270 byts long so the handler immediately fires the complete event, but with an error;
Transfer failed.java.lang.IllegalStateException: unexpected message type: DefaultHttpContent
which ich caused by the HttpObjectEncoder class that is part of the HttpServerCodec. for some reason the HttpChunkedInput passes a DefaultHttpContent object that seems to be not allowed.
My Pipe Looks like this
HttpServerCodec
HttpObjectAggregator
ChunkedWriteHandler
FileHandler
It looks like a pretty default setup to me. What am I doing wrong here?
UPDATE
I initialized my HttpResponse object for the headers like this:
HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
The problem is that you create a DefaultFullHttpResponse.
Please use: