FrameTooLongException Mime HTTP标头大小计算

时间:2015-08-04 18:47:25

标签: http netty mime

当收到带有netty客户端对象的响应时,我遇到了FrameTooLongException。在获取tcpdump之后,发现收到的响应是一个大型的Mutlipart Mime响应,大约有200个部分(每个都有一些短标题),但响应的实际HTTP标头非常小,并列为;

> Host: foobar.com:20804
> Accept: */*
> 
< HTTP/1.1 207 Multi-Status
< Date: Tue, 04 Aug 2015 19:44:09 GMT
< Vary: Accept
< Content-Type: multipart/mixed; boundary="63602357878446117"
< Content-Length: 33023

我在文档中找不到有关此内容的任何内容,但是在HTTP标头大小计算中使用了Mime部分标头,Netty是否会这样解析它?

我得到的例外情况如下:

io.netty.handler.codec.TooLongFrameException: HTTP header is larger than 8192 bytes.
        at io.netty.handler.codec.http.HttpObjectDecoder$HeaderParser.newException(HttpObjectDecoder.java:787)
        at io.netty.handler.codec.http.HttpObjectDecoder$HeaderParser.process(HttpObjectDecoder.java:779)
        at io.netty.buffer.AbstractByteBuf.forEachByteAsc0(AbstractByteBuf.java:1022)
        at io.netty.buffer.AbstractByteBuf.forEachByte(AbstractByteBuf.java:1000)
        at io.netty.handler.codec.http.HttpObjectDecoder$HeaderParser.parse(HttpObjectDecoder.java:751)
        at io.netty.handler.codec.http.HttpObjectDecoder.readHeaders(HttpObjectDecoder.java:545)
        at io.netty.handler.codec.http.HttpObjectDecoder.decode(HttpObjectDecoder.java:221)
        at io.netty.handler.codec.http.HttpClientCodec$Decoder.decode(HttpClientCodec.java:136)
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:315)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:229)
        at io.netty.channel.CombinedChannelDuplexHandler.channelRead(CombinedChannelDuplexHandler.java:147)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:339)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324)
        at io.netty.handler.ssl.SslHandler.unwrap(SslHandler.java:1044)
        at io.netty.handler.ssl.SslHandler.decode(SslHandler.java:934)
        at io.netty.handler.codec.ByteToMessageDecoder.callDecode(ByteToMessageDecoder.java:315)
        at io.netty.handler.codec.ByteToMessageDecoder.channelRead(ByteToMessageDecoder.java:229)
        at io.netty.channel.AbstractChannelHandlerContext.invokeChannelRead(AbstractChannelHandlerContext.java:339)
        at io.netty.channel.AbstractChannelHandlerContext.fireChannelRead(AbstractChannelHandlerContext.java:324)
        at io.netty.channel.DefaultChannelPipeline.fireChannelRead(DefaultChannelPipeline.java:847)
        at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:131)
       at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468)
        at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382)
        at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354)
        at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111)

1 个答案:

答案 0 :(得分:1)

Http标头终止于2 cr / lf(例如在您的示例中为Accept和HTTP之间),标头应以“起始行”(HTTP / 1.1 ...)开头。

因此,我看到您的示例有两个问题:

  1. 您的标头无法正常启动:HTTP / 1.1应该是第一行,稍后是您的accept和其他主机标头参数。
  2. 你的回答可能有一些错误,你的标题和正文之间没有2 cr /,因此导致正文的解码就好像它是标题的一部分一样,所以异常......