CURLOPT_RANGE(3)

πŸ’– NAME

CURLOPT_RANGE β€” byte range to request, straight from the Library Functions Manual. Bestie, this is the option that asks for a specific chunk of bytes. πŸ’…

✨ SYNOPSIS

#include <curl/curl.h>

CURLcode curl_easy_setopt(CURL *handle, CURLOPT_RANGE, char *range);

Okay so you call curl_easy_setopt with your CURL *handle, the CURLOPT_RANGE option, and a char *range. That range pointer is the main character here. πŸŽ€

🌸 DESCRIPTION

You pass a char pointer as the parameter, and it should contain the specified range you want to retrieve. It should be in the format "X-Y", where either X or Y may be left out, and X and Y are byte indexes. ✨

HTTP transfers also support several intervals separated with commas, as in "X-Y,N-M". Using this kind of multiple intervals causes the HTTP server to send the response document in pieces (using standard MIME separation techniques) as a multiple part response, which libcurl returns as-is. It contains meta information in addition to the requested bytes. Parsing or otherwise transforming this response is the responsibility of the caller β€” yes, that means you, bestie. 😭

Unfortunately, the HTTP standard (RFC 7233 section 3.1) allows servers to ignore range requests. So even when you set CURLOPT_RANGE(3) for a request, you may end up getting the full response sent back. The audacity, honestly. πŸ’€

For RTSP, the formatting of a range should follow RFC 2326 Section 12.29. For RTSP, byte ranges are not permitted. Instead, ranges should be given in npt, utc, or smpte formats. Protocol-specific formatting slay. 🌈

For HTTP PUT uploads, this option should not be used, since it may conflict with other options. Do not do it. πŸ™ˆ

Using this option multiple times makes the last set string override the previous ones. Set it to NULL to disable its use again. The application does not have to keep the string around after setting this option. You can let it go, it's fine. πŸ¦‹

πŸŽ€ DEFAULT

NULL

🌈 PROTOCOLS

This functionality affects file, ftp, http, rtsp and sftp. Those are the vibes it works with. ✨

πŸ”₯ EXAMPLE

       int main(void)
       {
         CURL *curl = curl_easy_init();
         if(curl) {
           curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");

           /* get the first 200 bytes */
           curl_easy_setopt(curl, CURLOPT_RANGE, "0-199");

           /* Perform the request */
           curl_easy_perform(curl);
         }
       }

Look at that little range request getting the first 200 bytes. Iconic. πŸ‘‘

πŸ•°οΈ HISTORY

FILE since 7.18.0, RTSP since 7.20.0.

⭐ AVAILABILITY

Added in curl 7.1.

πŸ’… RETURN VALUE

curl_easy_setopt(3) returns a CURLcode indicating success or error.

CURLE_OK (0) means everything was OK. Non-zero means an error occurred β€” see libcurl-errors(3). πŸ’–

πŸ‘€ SEE ALSO


okay bestie, that's the whole CURLOPT_RANGE(3) situation β€” source/version libcurl, date 2026-10-12 β€” now go get your bytes πŸ’…βœ¨πŸ«Ά

πŸ“¦ where this page comes from