yhirose/cpp-httplib

Handling an open ended range request for large data

hstejas opened this issue · 2 comments

This more of a question regarding range requests on the server

When i have a pretty big data, say 1GB and i get a range request Range: 0-.
I assume its valid to send a small part of it and complete the request, say reply with only 2MB with e.g. Content-Range: bytes 0-<2MB>/<1GB>.

So the question is how do I achieve it?
Just calling set_content replies with a misleading <size> of 2MB. calling set_content_provider with the length argument forces me to send the full 1GB.

Thanks

Range: 0- means data from 0 byte offset to the end of the data.
https://www.rfc-editor.org/rfc/rfc9110#name-range-requests

Thanks for responding,
The way i read it here, the rfc is not very strict about it

so Range: 0- could be treated as Range: 0-100 if its convenient, the client can later request for Range: 101-

Quoting lines to support the reasoning

https://www.rfc-editor.org/rfc/rfc9110#name-206-partial-content

However, a server might want to send only a subset of the data requested for reasons of its own, such as temporary unavailability, cache efficiency, load balancing, etc. Since a 206 response is self-descriptive, the client can still understand a response that only partially satisfies its range request.

The above does not imply that a server will send all requested ranges. In some cases, it may only be possible (or efficient) to send a portion of the requested ranges first, while expecting the client to re-request the remaining portions later if they are still desired (see Section 15.3.7).