Skip to content

If-Range

Description

The If-Range request header is an HTTP conditional request header used to make range requests more efficient. It allows a client to request only a portion of a resource, but only if it has not been modified since a specified time or if it matches a specific entity tag (ETag).

This header is commonly used for resuming interrupted downloads or for partial content retrieval when caching mechanisms are in place. If the resource has not changed, the server will return only the requested range. If the resource has changed, the server will ignore the range request and return the full resource instead.

Syntax

The If-Range header can be used in an HTTP request as follows:

Using an ETag:

If-Range: "etag_value"

Using a date:

If-Range: Mon, 18 Feb 2025 12:00:00 GMT

This header is typically used in combination with the Range header:

Range: bytes=500-999
If-Range: "etag_value"

Examples

Requesting a Partial Resource with an ETag

A client requests a specific byte range, but only if the resource has not changed.

Client Request:

GET /video.mp4 HTTP/1.1
Host: example.com
Range: bytes=500-999
If-Range: "abc123"

Server Response (If ETag Matches - Partial Content Returned):

HTTP/1.1 206 Partial Content
Content-Range: bytes 500-999/4000
Content-Type: video/mp4

[binary data]

Server Response (If ETag Does Not Match - Full Resource Returned):

HTTP/1.1 200 OK
Content-Type: video/mp4

[entire file]

Requesting a Partial Resource with a Date

A client requests a byte range, but only if the resource has not been modified since the given date.

Client Request:

GET /document.pdf HTTP/1.1
Host: example.com
Range: bytes=1000-1999
If-Range: Mon, 18 Feb 2025 12:00:00 GMT

Server Response (If Resource Has Not Changed - Partial Content Returned):

HTTP/1.1 206 Partial Content
Content-Range: bytes 1000-1999/10000
Content-Type: application/pdf

[binary data]

Server Response (If Resource Has Changed - Full Resource Returned):

HTTP/1.1 200 OK
Content-Type: application/pdf

[entire file]

Summary

The If-Range request header is a useful tool for optimizing network efficiency, particularly in scenarios where partial content retrieval is needed. By ensuring that range requests are only fulfilled when the resource remains unchanged, it helps prevent data inconsistencies and unnecessary re-downloads. This header is essential for applications that require efficient bandwidth management, such as video streaming, file downloads, and caching mechanisms.