Note that there are some explanatory texts on larger screens.

plurals
  1. POmissing EOF from HTTP stream without Transfer-Encoding chunked
    text
    copied!<p>I am streaming content over HTTP with Netty 4. The content is generated dynamically, so there is no way to know the content length ahead of time. My existing non-netty code writes to an <code>OutputStream</code>, so I wrote a simple wrapper around an <code>OutputStream</code> that takes the writes and puts them in a <code>ByteBuf</code>, and when that's full, it writes it as the payload of <code>DefaultHttpContent</code>. Prior to any writes to the <code>OutputStream</code>, I send a non-full <code>HttpResponse</code> w/ an <code>OK</code> status code.</p> <p>When the close is called on the stream, i send whatever is in the local ByteBuf that has not been sent, and then <code>LastHttpContent.EMPTY_LAST_CONTENT</code>.</p> <p>What I see with wget is that it gets all the bytes, but then sits and waits for the end of the stream. If I put the Transfer-Encoding: Chunked header in the initial response, things work perfectly.</p> <p>I can see some differences in the handling of the LastHttpContent message in <code>HttpObjectEncoder</code> which is what clued me in about trying the chunked transfer header. What I'm unclear about is what the difference is and why the EOF seems to not be sent w/o the header, even though all the bytes are sent <em>and</em> I'm sending <code>LastHttpContent.EMPTY_LAST_CONTENT</code></p> <p><strong>EDIT:</strong></p> <p>I am able to reproduce this behavior via a simple modification to <code>HttpStaticFileServerHandler</code> in the Netty 4 examples. I am using <a href="https://gist.github.com/mhgrove/6464352" rel="nofollow">this class</a> to send the file back to the client, <a href="https://gist.github.com/mhgrove/6464409" rel="nofollow">this</a> (requires Guava) is my modified <code>channelRead0</code> method from <code>HttpStaticFileServerHandler</code> which instead of setting the content length &amp; writing the file directly to the channel, it copies the File to the channel via <code>ByteBuffHttpOutputStream</code> which sends 1 MB chunks of output via <code>DefaultHttpContent</code> and on <code>close</code> sends a <code>LastHttpContent.EMPTY_LAST_CONTENT</code>. If I remove the setting of the <code>Transfer-Encoding</code> header: (<code>response.headers().set(Names.TRANSFER_ENCODING, Values.CHUNKED)</code>) then using wget to grab the file never completes. afaict, I'm sending the stream correctly, and it <em>looks</em> like <code>HttpObjectEncoder</code> should be handling the <code>LastHttpContent</code> correctly, but yet, no EOF.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload