What is the difference between HTTP headers Content-Range
and Range
? When should each be used?
I am trying to stream an audio file from a particular byte offset. Should I use Content-Range
or Range
header?
What is the difference between HTTP headers Content-Range
and Range
? When should each be used?
I am trying to stream an audio file from a particular byte offset. Should I use Content-Range
or Range
header?
Range is used in the request, to ask for a particular range (or ranges) of bytes. Content-Range is used in the response, to indicate which bytes the server is giving you (which may be different than the range you requested), as well as how long the entire content is (if known).
Actually, the accepted answer is not complete. Content-Range is not only used in responses. It is also legal in requests that provide an entity body.
For example, an HTTP PUT provides an entity body, it might provide only a portion of an entity. Thus the PUT request can include a Content-Range header indicating to the server where the partial entity body should be merged into the entity.
For example, let's first create and then append to a file using HTTP:
Request 1:
PUT /file HTTP/1.1
Host: server
Content-Length: 1
a
Request 2:
PUT /file HTTP/1.1
Host: server
Content-Range: bytes 1-2/*
Content-Length: 1
a
How, let's see the file's contents...
Request 3:
GET /file HTTP/1.1
Host: server
HTTP/1.1 200 OK
Content-Length: 2
aa
This allows random file access, both READING and WRITING over HTTP. I just wanted to clarify, as I was researching the use of Content-Range in a WebDAV client I am developing, so perhaps this expanded information will prove useful to somebody else.
Content-Range
header to requests, but binds it to a "partial entity-body". It's actually very common to use the feature to facilitate upload resume or chunked upload. –
Weiser Content-Range
can be used in requests. See the section on PUT method: w3.org/Protocols/rfc2616/rfc2616-sec9.html#sec9.6 - The recipient of the entity MUST NOT ignore any Content-* (e.g. Content-Range) headers that it does not understand or implement and MUST return a 501 (Not Implemented) response in such cases.
- A request might contain the Content-Range
header and the server SHOULD take it into account. –
Siliqua Content-Range: 1-1/*
for appending a single byte. –
Phillipp PUT
requests back/forth due to ignoring Content-*
they don't understand -- is negated by Microsoft employing exclusively their own infrastructure, which may or may not be using HTTP proxies altogether, for OneDrive, at least. Meaning they've got a single HTTP server entity that is responsible to duly respond to PUT requests with Content-Range
headers, correctly. –
Dineen Content-Range
with PUT
for file uploads >= 3MB, see Attach large files to Outlook messages or events. –
Unparliamentary Range is used in the request, to ask for a particular range (or ranges) of bytes. Content-Range is used in the response, to indicate which bytes the server is giving you (which may be different than the range you requested), as well as how long the entire content is (if known).
© 2022 - 2024 — McMap. All rights reserved.