curl / Mailing Lists / curl-users / Single Mail


Re: libcurl - sample code for multiple out of order range requests from same url

From: Ray Satiro via curl-users <>
Date: Sat, 29 Jul 2017 03:20:20 -0400

On 7/27/2017 7:57 AM, Steve Williams wrote:
> To reply to my own query - have worked this a little further & figured
> out how to determine the range a write callback refers to - by adding
> a header callback and pulling the information from the relevant header
> line.
> Current issue is getting http range requests to do what I want. Seems
> the spec allows servers to second guess and deliver more than was
> requested which is *so* annoying. Almost annoying enough to drop back
> to sockets and write my own protocol that delivers what I actually
> asked for :)
> Any insight into how to get range requests to perform more
> deterministically would be appreciated.

AFAIK if you make a range request for a single part per request and you
get 206 in reply then that will be the content you requested, but yes
206 is not guaranteed. If you make a request for multiple parts per
request then detecting that all the parts are fulfilled will be
complicated based on my reading of RFC 7233 [1]. Offhand I don't know if
libcurl handles that. If you are requesting a single part in each
request you could test for 206 in the write callback instead of parsing
the Content-Range header.

size_t realsize = size * nmemb;
if(user->range) {
  long response_code = 0;
  curl_easy_getinfo(user->curl_handle, CURLINFO_RESPONSE_CODE,
  /* don't write server responses other than 206 partial */
  if(response_code != 206)
    return realsize;
write here

You can pass a user pointer to the write callback by using

RTSP ranging is different, hopefully someone experienced with it can
chime in.


Received on 2017-07-29