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
CURLOPT_LOW_SPEED_LIMIT(3)CURLOPT_MAXFILESIZE_LARGE(3)CURLOPT_MAX_RECV_SPEED_LARGE(3)CURLOPT_RESUME_FROM(3)
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
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- fedora 44: libcurl-devel 8.18.0-14.fc44 Β· curl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms