Netty 4 HttpChunkedInput throws “unexpected message type: DefaultHttpContent” in HttpObjectEncoder

本小妞迷上赌 提交于 2020-01-07 03:07:06

问题


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);

回答1:


The problem is that you create a DefaultFullHttpResponse.

Please use:

HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);


来源:https://stackoverflow.com/questions/33784983/netty-4-httpchunkedinput-throws-unexpected-message-type-defaulthttpcontent-in

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!