http-kit/http-kit — pull request #84 by rufoa (2013-09-13 22:17:24+00:00)
Title: Bugfix: HTTP streaming connection closes after first chunk with Connection: Close header

When using HTTP streaming (chunked responses) a problem arises when the client explicitly sets the `Connection: Close` header. The server closes the connection after the first chunk is sent, rather than keeping it open until after the last chunk is sent.

This is because `tryWrite` in `HttpServer.java` only checks that `atta.isKeepAlive()` is false before closing the connection. If we are doing HTTP streaming then it should also check that the response we are writing is the last chunk.

My patch corrects this by adding an extra `close` parameter to `tryWrite` which defaults to `true`, but uses the local value of `close` in the `firstWrite` and `writeChunk` methods.

The patch is not ideal - specifically I am not keen on the overloaded function - but it should indicate the changes which are required.

Many thanks!