izqui / Taylor

A lightweight library for writing HTTP web servers with Swift
MIT License
926 stars 79 forks source link

Support HTTP requests that are sent in arbitrary number of chunks #48

Open arrizer opened 8 years ago

arrizer commented 8 years ago

The current implementation of the SocketServer only supports HTTP requests that are sent in 1 or 2 chunks, with the additional requirement of the "Content-Length" header being fully contained in the first chunk for POST and PUT requests. HTTP requests however can be sent in an arbitrary number of chunks and a server must only process the request, after all headers and the full body was received.

On a fast localhost connection an additional problem occurs: The current implementation checks if the body was contained in the first chunk, if not, it just calls read() on the socket. But in many cases, the body data is not available on the socket yet, which will result in a socket read error 35 (EAGAIN) and the body data is silently dropped.

I issues a pull request that should fix the above issues. There are still some memory leaks when handling massive amounts of requests, those should be addressed separately.

arrizer commented 8 years ago

I just updated the pull request and resolved merge conflicts.