diff options
author | Lars-Dominik Braun <lars@6xq.net> | 2013-05-08 18:55:16 +0200 |
---|---|---|
committer | Lars-Dominik Braun <lars@6xq.net> | 2013-05-08 20:44:47 +0200 |
commit | ea4324bbb6d3388c39f80906c85501feee3cb541 (patch) | |
tree | f0aeb9cbdba2a0aa0469ae497744dce30c47d7b3 /src/libwaitress/waitress.c | |
parent | b379ce9595e2d23363184a6be7d12315f1e7b910 (diff) | |
download | pianobar-ea4324bbb6d3388c39f80906c85501feee3cb541.tar.gz pianobar-ea4324bbb6d3388c39f80906c85501feee3cb541.tar.bz2 pianobar-ea4324bbb6d3388c39f80906c85501feee3cb541.zip |
waitress: Close connection if body has been received
Now libwaitress won’t wait until the server closes the connection if the
request body has been received. Multiple requests per connection are not
supported anyway. Fixes #321. Thanks to Michael Stowe.
Diffstat (limited to 'src/libwaitress/waitress.c')
-rw-r--r-- | src/libwaitress/waitress.c | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/src/libwaitress/waitress.c b/src/libwaitress/waitress.c index 3d01198..771c54f 100644 --- a/src/libwaitress/waitress.c +++ b/src/libwaitress/waitress.c @@ -703,6 +703,7 @@ static void WaitressHandleHeader (WaitressHandle_t *waith, const char * const ke if (strcaseeq (key, "Content-Length")) { waith->request.contentLength = atol (value); + waith->request.contentLengthKnown = true; } else if (strcaseeq (key, "Transfer-Encoding")) { if (strcaseeq (value, "chunked")) { waith->request.dataHandler = WaitressHandleChunked; @@ -1064,6 +1065,12 @@ static WaitressReturn_t WaitressReceiveResponse (WaitressHandle_t *waith) { /* go on */ break; } + if (waith->request.contentLengthKnown && + waith->request.contentReceived >= waith->request.contentLength) { + /* don’t call read() again if we know the body’s size and have all + * of it already */ + break; + } READ_RET (buf, WAITRESS_BUFFER_SIZE-1, &recvSize); } while (recvSize > 0); @@ -1083,6 +1090,7 @@ WaitressReturn_t WaitressFetchCall (WaitressHandle_t *waith) { waith->request.dataHandler = WaitressHandleIdentity; waith->request.read = WaitressOrdinaryRead; waith->request.write = WaitressOrdinaryWrite; + waith->request.contentLengthKnown = false; if (waith->url.tls) { gnutls_init (&waith->request.tlsSession, GNUTLS_CLIENT); |