HTTP range request

What it is

An HTTP range request asks a server to send part of a selected
representation. For a byte range, the client names one or more
portions of the representation's data. A reader can request the
beginning of a large file, continue an interrupted download or
retrieve the part that contains information it needs. The server
chooses whether to support the request and describes the result
through response status and headers.

For a successful partial response to a single byte range, status 206
indicates that the body is partial. Content-Range describes which
bytes it carries and can give the full length where known. A
multiple-range response can use a multipart body with details for
each part. A server that ignores the range can deliver a complete
response with status 200. The client has to interpret the actual
response before deciding how to store the bytes.

The ranges refer to bytes of the selected representation. A client
that joins pieces from different versions can produce a damaged
file. An appropriate validator or an If-Range condition can help tie
a resumed transfer to the version the client already has. If the
condition no longer holds, the client may need to replace its
previous partial copy with the newly delivered complete
representation.

Why it matters

Large resources can be expensive to transfer repeatedly. A reader
may open a document on a connection that drops briefly and want to
continue after reconnecting. A media player can want to seek ahead.
Partial transfer supports those experiences when both ends agree
about the resource and its byte layout. Correct handling preserves
the user's progress across interruptions and versions.

The service also has to handle ranges at the same boundary that
ordinarily serves the file. Access rules apply to the operation
before selecting a portion. A proxy or cache can affect which bytes
represent the resource and what metadata the client receives. Test
the public path separately from direct storage access. Include the
transformations and conditions a real client encounters when it
requests a range.

Clients differ in what they require. One reader can use a full
response when partial transfer is unavailable. Another may use
several requests during a client-side operation. Document the
choices that the service supports and check how clients respond when
it refuses or ignores a range. Reliable downloads need a coherent
plan for the whole request lifecycle.

What it looks like in practice

Imagine a public route serving a generated PDF. Begin with a normal
GET to record its media type, length and validator. Request a small
interval within the file and inspect the response. If the server
supports the request, compare the returned bytes with the
corresponding part of the complete file and check the declared
positions. If the server sends a full response, verify that the
client replaces the partial file with the complete response.

Test a later request after changing the representation through the
normal release path. Keep an earlier partial copy and send the
condition the client would normally use to resume. The result should
establish whether those earlier bytes still belong to the current
representation. Add an interval past the end of the file. A server
can respond with 416 when the requested ranges are unsatisfiable. A
client should handle that result and find out whether its local file
is already complete or needs a new transfer.

Engineer's PDF print stylesheet case study describes making document
exports readable and predictable on paper. Partial transfer is a
different property of delivering a generated document. The
illustrative check ties it to the exact PDF bytes through the public
route. It also verifies a useful fallback for clients that receive
the whole file.

When a cache is on the route, test both an initial full retrieval
and a partial request starting from an empty cache. Record which
layer responded and whether the validator and returned interval
agree. A status code without a byte comparison gives weak evidence
about which part actually arrived at the client.

Where it goes wrong

A download program can append every response to the bytes it already
has. When the server replies with a fresh full representation, the
resulting file can contain two versions. Branch on the response
status and validate the returned positions before appending. If the
server reports a different representation identity, begin with a new
output or follow the documented recovery policy.

Compression can make range checks confusing. A transfer can select a
different representation from the stored one when the request
changes its accepted encoding. The recorded byte positions have
meaning only for the bytes they describe. Keep request conditions
and relevant selection headers together and exercise the variant
that the real client uses.

A downloaded slice can be checked using both content and arithmetic.
For a single returned range, the positions are inclusive, so an
interval from position zero through position nine should carry ten
bytes. Compare the expected length with the bytes actually received
and confirm the positions match what the client will append or
display. A test that checks only the total length can miss an
interval of the right size from the wrong part of the file.

Finally, handle bounded and exceptional inputs. Some clients ask for
several ranges. A service can choose limits and report a result
appropriate to its actual support. Include a normal interval, an
invalid or unsatisfiable one and an interrupted response in the test
suite. Give operators evidence about representation identity and
final file integrity, since those are what make a successful partial
response useful.

Further reading

  * RFC 9110 range requests. Defines range fields, conditions and
partial content semantics.

  * Mozilla's HTTP range requests guide. Explains practical partial
transfers and responses.

  * libcurl CURLOPT_RANGE. Documents one way clients request a
range.

hThis page on the web	URL:https://engineer.company/glossary/http-range-request/	engineer.company	70
