Range header
Baseline Widely available
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
The HTTPRangerequest header indicates the part of a resource that the server should return.Several parts can be requested at the same time in oneRange header, and the server may send back these ranges in a multipart document.If the server sends back ranges, it uses the206 Partial Content status code for the response.If the ranges are invalid, the server returns the416 Range Not Satisfiable error.
A server that doesn't support range requests may ignore theRange header and return the whole resource with a200 status code.Older browsers used a response header ofAccept-Ranges: none to disable features like 'pause' or 'resume' in download managers, but since a server ignoring theRange header has the same meaning as responding withAccept-Ranges: none, the header is rarely used in this way.
Currently onlybytes units are registered which areoffsets (zero-indexed & inclusive).If the requested data has acontent coding applied, each byte range represents the encoded sequence of bytes, not the bytes that would be obtained after decoding.
The header is aCORS-safelisted request header when the directive specifies a single byte range.
| Header type | Request header |
|---|---|
| Forbidden request header | No |
In this article
Syntax
Range: <unit>=<range-start>-Range: <unit>=<range-start>-<range-end>Range: <unit>=<range-start>-<range-end>, …, <range-startN>-<range-endN>Range: <unit>=-<suffix-length>Directives
<unit>The unit in which ranges are defined.Currently only
bytesare a registered unit.<range-start>An integer in the given unit indicating the start position of the request range.
<range-end>An integer in the given unit indicating the end position of the requested range.This value is optional and, if omitted, the end of the resource is used as the end of the range.
<suffix-length>An integer indicating the number of units at the end of the resource to return.
Examples
The following examples show how to make requests using theRange header for CORS-safelisted requests, and for requesting multiple ranges.Other examples can be found in theHTTP range requests guide.
Single byte ranges and CORS-safelisted requests
TheRange header is aCORS-safelisted request header when the value is a single byte range.This means that it can be used in cross-origin requests without triggering apreflight request, which is useful for requesting media and resuming downloads.
The following example requests the first 500 bytes of a resource:
Range: bytes=0-499To request the second 500 bytes:
Range: bytes=500-999Omitting the end position requests all remaining units of the resource, so the last 100 bytes of a resource with a length of 1000 bytes can be requested using:
Range: bytes=900-Alternatively, if it's unknown how large a resource is, the lastn bytes can be requested using a suffix range of-n:
Range: bytes=-100Requesting multiple ranges
Given a resource with a length of 10000 bytes, the following example requests three separate ranges;200-999 (800 bytes),2000-2499 (500 bytes), and finally9500-.The ranges-specifier value9500- omits an end position which indicates that all bytes from 9500 onward are part of the third range (500 bytes).
Range: bytes=200-999, 2000-2499, 9500-This example requests the first 500 and last 500 bytes of the file.The request may be rejected by the server if these ranges overlap (if the requested resource was less than 1000 bytes long, for instance).
Range: bytes=0-499, -500Checking if a server supports range requests
The following curl command makes aHEAD request for an image:
curl -v --http1.1 -I https://i.imgur.com/z4d4kWk.jpg# or using the OPTIONS method:# curl -v --http1.1 -X OPTIONS https://i.imgur.com/z4d4kWk.jpgThis results in the following HTTP request:
HEAD /z4d4kWk.jpg HTTP/1.1Host: i.imgur.comUser-Agent: curl/8.7.1Accept: */*The server responds with a200 response, and theAccept-Ranges: bytes header is present (some headers are omitted for brevity):
HTTP/1.1 200 OKConnection: keep-aliveContent-Length: 146515Content-Type: image/jpeg…Accept-Ranges: bytesFetching a range from a blob URL
Theblob: URL also supports range requests by usingfetch().
const blob = new Blob(["Hello, world!"], { type: "text/plain" });const url = URL.createObjectURL(blob);fetch(url, { headers: { Range: "bytes=7-11", },}) .then((response) => response.text()) .then((text) => console.log(text)); // "world"Specifications
| Specification |
|---|
| HTTP Semantics> # field.range> |
Browser compatibility
See also
If-Rangeconditional request headerContent-Rangeresponse headerContent-TypeAccept-Ranges206 Partial Content416 Range Not Satisfiable- HTTP range requests guide
- CORS-safelisted request header