If-Range
Resuming a partial download after a resource changed leads to corrupted data. The HTTP If-Range request header prevents this by making a Range request conditional on a validator match, returning the requested byte range when valid or the full resource when the content has changed.
Usage
Clients use If-Range when resuming a partial download or fetching a specific byte range from a resource obtained earlier. The header carries either an ETag value or a Last-Modified date as a validator. Only one form is allowed per request.
The key difference from If-Match is what happens when the condition fails. An If-Match failure produces a 412 Precondition Failed error and stops the request. An If-Range failure succeeds gracefully: the server ignores the Range header and returns the entire resource with a 200 status. This makes If-Range safer for download resumption because the client always receives usable data.
A conditional request with If-Range requires a Range header in the same request. Without a Range header, the server ignores If-Range entirely.
Directives
entity-tag
An ETag value previously received from the
server. The value is a quoted string and must be a
strong validator: weak ETags prefixed with W/ are
not permitted in If-Range.
If-Range: "abc123"
HTTP-date
A Last-Modified timestamp in the standard HTTP date format. The server compares this date against the current modification date of the resource.
If-Range: Wed, 01 Jun 2022 08:00:00 GMT
Note
An If-Range header carries either an ETag or a date. Both forms are not allowed in the same request.
Example
A client previously downloaded part of a large file and received an ETag with the initial response. To resume the download starting at byte 1048576, the client sends both the Range header and an If-Range header with the stored ETag. If the file has not changed, the server responds with 206 Partial Content.
GET /releases/archive.tar.gz HTTP/1.1
Host: cdn.example.re
Range: bytes=1048576-
If-Range: "a1b2c3d4e5"
When the resource has changed since the initial download, the ETag no longer matches. The server discards the Range and responds with the complete file and a 200 status.
HTTP/1.1 200 OK
Content-Length: 52428800
ETag: "f6g7h8i9j0"
A date-based validator works the same way. This request resumes a download only if the file has not been modified since the specified timestamp.
GET /data/export.csv HTTP/1.1
Host: api.example.re
Range: bytes=524288-
If-Range: Sat, 15 Feb 2025 12:00:00 GMT