问题描述
我写了一个netty 4.0.33 https文件服务器,该服务器假定以文件夹形式发送文件. 文件服务器示例在使用https处理此类响应时显示:
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()
);
我测试过的文件只有270个字节,因此处理程序立即触发了complete事件,但出现错误;
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
这是由 HttpObjectEncoder 类引起的,该类是HttpServerCodec的一部分.出于某些原因, HttpChunkedInput 传递了一个似乎不允许的 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.
我的烟斗看起来像这样
HttpServerCodec
HttpObjectAggregator
ChunkedWriteHandler
FileHandler
在我看来,这是一个非常漂亮的默认设置.我在这里做什么错了?
It looks like a pretty default setup to me. What am I doing wrong here?
更新
我为这样的标题初始化了HttpResponse对象:
I initialized my HttpResponse object for the headers like this:
HttpResponse response = new DefaultFullHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
推荐答案
问题是您创建了DefaultFullHttpResponse.
The problem is that you create a DefaultFullHttpResponse.
请使用:
HttpResponse response = new DefaultHttpResponse(HttpVersion.HTTP_1_1, HttpResponseStatus.OK);
这篇关于Netty 4 HttpChunkedInput抛出“意外消息类型:DefaultHttpContent";在HttpObjectEncoder中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!