HTTP Service Metadata#
OpenDAL's HTTP-family backends (services/http, ghac, vercel_artifacts) need to return a complete file size (content_length) on stat and read operations, but HTTP responses from CDNs and object stores often omit Content-Length โ notably when chunked transfer-encoding (HTTP/1.1) or stream framing (HTTP/2) is in use. Each backend handles this gap differently.
Shared Header Parser#
All backends start from parse_into_metadata in core/src/raw/http_util/header.rs. It builds a Metadata struct by independently parsing standard headers:
parse_content_lengthโ setscontent_lengthif the header is present and valid.parse_content_rangeโ setscontent_rangeif the header is present.
The shared parser stores both values as-is without reconciling one against the other . Any correction of content_length from content_range is left to the individual backend.
Generic HTTP Backend (services/http)#
The HTTP backend's stat issues a HEAD request and calls parse_into_metadata directly on the response headers. It performs no further size reconciliation. If the server omits Content-Length (e.g., a chunked or HTTP/2 HEAD response), the returned Metadata will have no content_length. This is an inherent limitation of the pure HEAD-based approach: the backend cannot fall back to body inspection or Content-Range because a HEAD response carries no body and, without a byte-range request, no Content-Range header either.
For reads, http_get accepts both 200 OK and 206 Partial Content, streaming the body directly โ it does not attempt to derive metadata from the read response.
GHAC Backend: Range: bytes=0-0 Stat Pattern#
The GitHub Actions Cache backend demonstrates the canonical workaround for CDNs that restrict HEAD or serve Content-Length-free responses. Its ghac_stat sends a GET with Range: bytes=0-0 instead of a HEAD:
GET <download-url>
Range: bytes=0-0
A conforming server responds 206 Partial Content with a Content-Range: bytes 0-0/<total> header, where <total> is the full object size. The backend then overwrites content_length from content_range.size(), ensuring the returned metadata always reflects the complete object size rather than the 1-byte range response body. This works for servers regardless of whether they would send Content-Length on a range response.
Note: The GHAC backend's reconciliation code uses
.expect()on bothcontent_rangeand its.size(). A response missing or malformedContent-Rangewill panic rather than return an error.
Vercel Artifacts Backend#
The Vercel Artifacts backend currently uses a plain HEAD + parse_into_metadata, mirroring the generic HTTP backend. It relies on the server providing Content-Length in the HEAD response. PR #7793 explored switching to a Range: bytes=0-0 GET (deriving total size from Content-Range, with a body-length fallback for 200 OK responses where the server ignores the range), but the current codebase reflects the simpler HEAD approach.
How Content-Range vs. Content-Length Differ for Size#
On a range request, Content-Length reports the byte count of the returned range (e.g., 1 for a bytes=0-0 request), not the total object size. Content-Range carries the total in its /<total> component. Backends that issue range requests for stat purposes must read size from Content-Range, not Content-Length.
Key Source Files#
| File | Purpose |
|---|---|
core/src/raw/http_util/header.rs | Shared header parsers and parse_into_metadata |
core/src/services/http/backend.rs | Generic HTTP backend stat/read |
core/src/services/ghac/backend.rs | GHAC stat with Content-Range reconciliation |
core/src/services/ghac/core.rs | ghac_stat issuing Range: bytes=0-0 GET |
core/src/services/vercel_artifacts/backend.rs | Vercel Artifacts stat (HEAD-based) |