Skip to content

RFC 7233 - Range Requests #978

@magne4000

Description

@magne4000

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions