{"thread":{"id":"40682","subject":"[PATCH] http.c: use CURLOPT_RANGE for range requests","startedAt":"2015-10-30T22:41:28Z","lastAt":"2015-10-30T22:43:26Z","messageCount":2,"participants":["David Turner"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"272593","messageId":"1446244888-32610-1-git-send-email-dturner@twopensource.com","threadId":"40682","inReplyTo":null,"subject":"[PATCH] http.c: use CURLOPT_RANGE for range requests","fromName":"David Turner","fromEmail":"dturner@twopensource.com","sentAt":"2015-10-30T22:41:28Z","receivedAt":"2015-10-30T22:41:28Z","isPatch":true,"sender":{"key":"novalis@novalis.org","avatar":"https://avatars.githubusercontent.com/u/77003?v=4"},"body":"A HTTP server is permitted to return a non-range response to a HTTP\nrange request (and Apache httpd in fact does this in some cases).\nWhile libcurl knows how to correctly handle this (by skipping bytes\nbefore and after the requested range), it only turns on this handling\nif it is aware that a range request is being made.  By manually\nsetting the range header instead of using CURLOPT_RANGE, we were\nhiding the fact that this was a range request from libcurl.  This\ncould cause corruption.\n\nSigned-off-by: David Turner <dturner@twopensource.com>\n---\n http.c | 5 +++--\n 1 file changed, 3 insertions(+), 2 deletions(-)\n\ndiff --git a/http.c b/http.c\nindex 0f924a8..303b388 100644\n--- a/http.c\n+++ b/http.c\n@@ -1202,8 +1202,9 @@ static int http_request(const char *url,\n \t\t\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION,\n \t\t\t\t\t fwrite);\n \t\t\tif (posn > 0) {\n-\t\t\t\tstrbuf_addf(&buf, \"Range: bytes=%ld-\", posn);\n-\t\t\t\theaders = curl_slist_append(headers, buf.buf);\n+\t\t\t\tstrbuf_addf(&buf, \"%ld-\", posn);\n+\t\t\t\tcurl_easy_setopt(slot->curl, CURLOPT_RANGE,\n+\t\t\t\t\t\t &buf.buf);\n \t\t\t\tstrbuf_reset(&buf);\n \t\t\t}\n \t\t} else\n-- \n2.4.2.691.g714732c-twtrsrc\n"},{"id":"272594","messageId":"1446245006.16007.0.camel@twopensource.com","threadId":"40682","inReplyTo":"1446244888-32610-1-git-send-email-dturner@twopensource.com","subject":"Re: [PATCH] http.c: use CURLOPT_RANGE for range requests","fromName":"David Turner","fromEmail":"dturner@twopensource.com","sentAt":"2015-10-30T22:43:26Z","receivedAt":"2015-10-30T22:43:26Z","isPatch":true,"sender":{"key":"novalis@novalis.org","avatar":"https://avatars.githubusercontent.com/u/77003?v=4"},"body":"Please disregard this; I noticed I missed a few instances.  Will reroll\nshortly.\n\n\nOn Fri, 2015-10-30 at 18:41 -0400, David Turner wrote:\n> A HTTP server is permitted to return a non-range response to a HTTP\n> range request (and Apache httpd in fact does this in some cases).\n> While libcurl knows how to correctly handle this (by skipping bytes\n> before and after the requested range), it only turns on this handling\n> if it is aware that a range request is being made.  By manually\n> setting the range header instead of using CURLOPT_RANGE, we were\n> hiding the fact that this was a range request from libcurl.  This\n> could cause corruption.\n> \n> Signed-off-by: David Turner <dturner@twopensource.com>\n> ---\n>  http.c | 5 +++--\n>  1 file changed, 3 insertions(+), 2 deletions(-)\n> \n> diff --git a/http.c b/http.c\n> index 0f924a8..303b388 100644\n> --- a/http.c\n> +++ b/http.c\n> @@ -1202,8 +1202,9 @@ static int http_request(const char *url,\n>  \t\t\tcurl_easy_setopt(slot->curl, CURLOPT_WRITEFUNCTION,\n>  \t\t\t\t\t fwrite);\n>  \t\t\tif (posn > 0) {\n> -\t\t\t\tstrbuf_addf(&buf, \"Range: bytes=%ld-\", posn);\n> -\t\t\t\theaders = curl_slist_append(headers, buf.buf);\n> +\t\t\t\tstrbuf_addf(&buf, \"%ld-\", posn);\n> +\t\t\t\tcurl_easy_setopt(slot->curl, CURLOPT_RANGE,\n> +\t\t\t\t\t\t &buf.buf);\n>  \t\t\t\tstrbuf_reset(&buf);\n>  \t\t\t}\n>  \t\t} else\n"}]}