I just began to work on implementing RFC 7233 about Range Requests.
Here is the analysis of how I think it should be implemented, followed by open points for which I will need help:
wrappers.make_conditional, new signature
def make_conditional(self, request_or_environ):
# becomes
def make_conditional(self, request_or_environ, accept_ranges=False,
complete_length=None, ignore_invalid_range_requests=True):
Also, make_conditional can now raise RequestedRangeNotSatisfiable exception.
datastructures: new Range.to_content_range_header(self, length) method, to generate Content-Range header value.
- Modify
exceptions.RequestedRangeNotSatisfiableon order to add Content-Range header support
http.is_resource_modified new signature
It should be able to take If-Range header into account, but in order to keep current behavior, disabled by default.
def is_resource_modified(environ, etag=None, data=None, last_modified=None):
# becomes
def is_resource_modified(environ, etag=None, data=None, last_modified=None, ignore_if_range=True):
With this implemented, the headers should all be OK, but now comes the question of the data itself.
If those headers are set (through make_conditional method), we must (?) ensure that the data sent by the server actually reflect those headers.
- Is this the role of Werkzeug, or should this be left to Flask ?
- If this should be implemented in Werkzeug, can we implement this in a generic way ?
- If we implement this in a generic way, we will not be able to use things like
seek() methods, and thus will make file (through wrap_file method) Range Requests pretty inneficient.
Edit: One answer can be to wrap responses, which are iterable, with a RangeWrapper. Its role would be to yield only the data contained within range. This RangeWrapper should also be able to support underlying streams that are seekable, that way we do not need to read and drop if not necessary.
I just began to work on implementing RFC 7233 about Range Requests.
Here is the analysis of how I think it should be implemented, followed by open points for which I will need help:
wrappers.make_conditional, new signatureAlso, make_conditional can now raise
RequestedRangeNotSatisfiableexception.datastructures: newRange.to_content_range_header(self, length)method, to generateContent-Rangeheader value.exceptions.RequestedRangeNotSatisfiableon order to addContent-Rangeheader supporthttp.is_resource_modifiednew signatureIt should be able to take
If-Rangeheader into account, but in order to keep current behavior, disabled by default.With this implemented, the headers should all be OK, but now comes the question of the data itself.
If those headers are set (through
make_conditionalmethod), we must (?) ensure that the data sent by the server actually reflect those headers.seek()methods, and thus will make file (throughwrap_filemethod) Range Requests pretty inneficient.Edit: One answer can be to wrap responses, which are iterable, with a
RangeWrapper. Its role would be to yield only the data contained within range. ThisRangeWrappershould also be able to support underlying streams that are seekable, that way we do not need to read and drop if not necessary.