Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
httpd: allow handler to not read an empty content
Starting in commit 4fa0e4b, an HTTP handler can read a request's body using an input stream instead of as a string. If the handler does not read the entire request body, the client can not send any further requests on this socket, so the server needs to close it. Conversely, if the handler *did* read the content, the server may keep the socket open. To check whether the handler read the content we checked the content stream's eof() state. However, this may only become true after a read() noticed the content has reached its end (specified by content-length or chunked encoding). But one interesting case we missed is a simple handler which assumes an empty request body, and doesn't bother to read it at all. In this case, even though the request is empty, and the handler didn't miss any content by not reading it, we close the connection. The solution in this patch is to replace the check for eof() by an attempt to read() from the content stream. In the typical case the handler either read the entire content or there was nothing to read in the first place, so this read() will return nothing immediately - and we allow reusing the connection. If anything is returned by the read(), it is ignored, and the connection is closed (we may still not read the entire content). Fixes #907 Refs scylladb/scylladb#8691 Signed-off-by: Nadav Har'El <nyh@scylladb.com> Message-Id: <20210523184038.425954-1-nyh@scylladb.com>
- Loading branch information