From a0ffc151036c3d63f153ab3a3d8a30994c47fedf Mon Sep 17 00:00:00 2001 From: Darshit Shah Date: Fri, 8 Dec 2017 18:13:00 +0100 Subject: [PATCH 1/2] Don't assume a 416 response has no body * http.c(gethttp): In case of a 416 response, try to drain the socket of any bytes before reusing the connection Reported-By: Iru Cai --- src/http.c | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/src/http.c b/src/http.c index 95d26258..e4ff0107 100644 --- a/src/http.c +++ b/src/http.c @@ -3969,11 +3969,16 @@ gethttp (const struct url *u, struct url *original_url, struct http_stat *hs, hs->res = 0; /* Mark as successfully retrieved. */ *dt |= RETROKF; - if (statcode == HTTP_STATUS_RANGE_NOT_SATISFIABLE) + + /* Try to maintain the keep-alive connection. It is often cheaper to + * consume some bytes which have already been sent than to negotiate + * a new connection. However, if the body is too large, or we don't + * care about keep-alive, then simply terminate the connection */ + if (keep_alive && + skip_short_body (sock, contlen, chunked_transfer_encoding)) CLOSE_FINISH (sock); else - CLOSE_INVALIDATE (sock); /* would be CLOSE_FINISH, but there - might be more bytes in the body. */ + CLOSE_INVALIDATE (sock); retval = RETRUNNEEDED; goto cleanup; } -- 2.15.1