FrameTooLongException Mime HTTP头大小计算

FrameTooLongException Mime HTTP头大小计算,http,netty,mime,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

当收到带有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头以2 cr/lf终止(例如,在您的示例中,在Accept和Http之间),并且头应以“起始行”(Http/1.1…)开始

因此,我在您的示例中看到了两个问题:

  • 您的头没有正确启动:HTTP/1.1应该是第一行,后面是accept和其他主机头参数
  • 可能是您的响应中出现了一些错误,例如头部和主体之间没有2 cr/of,从而导致主体解码,就像它是头部的一部分一样,因此异常

  • 你能发布一个标题到身体部位的例子吗?@FredericBrégier用标题信息编辑了问题,所以我从curl输出中复制了上面的标题。HTTP/1.1是第一行(由<符号表示,我将编辑)。根据你的第二点来看tcpdump,我确实看到了两行结尾。如果你有一台复制机,可能有兴趣在github以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)