Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

The parameter of ContentRange in quart.wrappers.Response._process_range_request is not correct. #331

Closed
jeffpeng3 opened this issue Apr 2, 2024 · 0 comments · Fixed by #332

Comments

@jeffpeng3
Copy link
Contributor

I've found a bug about ContentRange .

This is how it is used in quart:

self.headers["Accept-Ranges"] = accept_ranges
self.content_range = ContentRange(
    request_range.units,
    self.response.begin, # type: ignore
    self.response.end - 1, # type: ignore
    Completion length,
)
self.status_code = 206

Then in werkzeug it is converted to a header like this:

def to_header(self):
    """Converts the object back into an HTTP header."""
    ranges = []
    for begin, end in self.ranges:
        if end is None:
            ranges.append(f"{begin}-" if begin >= 0 else str(begin))
        else:
            ranges.append(f"{begin}-{end - 1}")
    return f"{self.units}={','.join(ranges)}"

For example, request header is 792-1955, request.range is 792-1955, response.begin and response.end are 792-1956, content_range:ContentRange is 792-1955, when converted to response header, it is 792-1954.

I think this is a quart problem, according to werkzeug's documentation, end is not included in the range, so end should not be reduced by one.

Environment:

  • Python version:3.12.2
  • Quart version:0.19.4
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant