1---
2c: Copyright (C) Daniel Stenberg, <daniel.se>, et al.
3SPDX-License-Identifier: curl
4Title: CURLOPT_RANGE
5Section: 3
6Source: libcurl
7See-also:
8  - CURLOPT_LOW_SPEED_LIMIT (3)
9  - CURLOPT_MAXFILESIZE_LARGE (3)
10  - CURLOPT_MAX_RECV_SPEED_LARGE (3)
11  - CURLOPT_RESUME_FROM (3)
12---
13
14# NAME
15
16CURLOPT_RANGE - byte range to request
17
18# SYNOPSIS
19
20~~~c
21#include <curl/curl.h>
22
23CURLcode curl_easy_setopt(CURL *handle, CURLOPT_RANGE, char *range);
24~~~
25
26# DESCRIPTION
27
28Pass a char pointer as parameter, which should contain the specified range you
29want to retrieve. It should be in the format "X-Y", where either X or Y may be
30left out and X and Y are byte indexes.
31
32HTTP transfers also support several intervals, separated with commas as in
33*"X-Y,N-M"*. Using this kind of multiple intervals causes the HTTP server
34to send the response document in pieces (using standard MIME separation
35techniques). Unfortunately, the HTTP standard (RFC 7233 section 3.1) allows
36servers to ignore range requests so even when you set CURLOPT_RANGE(3)
37for a request, you may end up getting the full response sent back.
38
39For RTSP, the formatting of a range should follow RFC 2326 Section 12.29. For
40RTSP, byte ranges are **not** permitted. Instead, ranges should be given in
41**npt**, **utc**, or **smpte** formats.
42
43For HTTP PUT uploads this option should not be used, since it may conflict with
44other options.
45
46Pass a NULL to this option to disable the use of ranges.
47
48The application does not have to keep the string around after setting this
49option.
50
51# DEFAULT
52
53NULL
54
55# PROTOCOLS
56
57HTTP, FTP, FILE, RTSP and SFTP.
58
59# EXAMPLE
60
61~~~c
62int main(void)
63{
64  CURL *curl = curl_easy_init();
65  if(curl) {
66    curl_easy_setopt(curl, CURLOPT_URL, "https://example.com");
67
68    /* get the first 200 bytes */
69    curl_easy_setopt(curl, CURLOPT_RANGE, "0-199");
70
71    /* Perform the request */
72    curl_easy_perform(curl);
73  }
74}
75~~~
76
77# AVAILABILITY
78
79FILE since 7.18.0, RTSP since 7.20.0
80
81# RETURN VALUE
82
83Returns CURLE_OK on success or
84CURLE_OUT_OF_MEMORY if there was insufficient heap space.
85