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

Consider FileResponse.chunk_size when handling multiple ranges #2703

Merged
merged 6 commits into from
Sep 25, 2024

Conversation

Kludex
Copy link
Member

@Kludex Kludex commented Sep 23, 2024

chunk = await file.read(min(self.chunk_size, end - start))
start += len(chunk)
await send({"type": "http.response.body", "body": chunk, "more_body": True})
if len(chunk) < self.chunk_size or start >= end:
Copy link
Member Author

@Kludex Kludex Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is the len(chunk) < self.chunk_size necessary?

I'm too tired, I'll check tomorrow. Just leaving my own comment here.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

it can be mathematically deduced that is not required

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, there is no need to check once len(chunk) < self.chunk_size

@Kludex
Copy link
Member Author

Kludex commented Sep 23, 2024

How do I have a different behavior in Python versions with this diff? 🤔

@Kludex
Copy link
Member Author

Kludex commented Sep 23, 2024

How do I have a different behavior in Python versions with this diff? 🤔

Coverage is not able to understand that the break was reached... @graingert do you know why? 🤔

starlette/responses.py Outdated Show resolved Hide resolved
starlette/responses.py Outdated Show resolved Hide resolved
starlette/responses.py Outdated Show resolved Hide resolved
@Kludex
Copy link
Member Author

Kludex commented Sep 24, 2024

@abersheeran @frostming anything else here, or we are good?

@frostming
Copy link
Contributor

lgtm

@Kludex Kludex changed the title Take in consideration the FileResponse.chunk_size on multiple ranges Consider FileResponse.chunk_size when handling multiple ranges Sep 25, 2024
@Kludex Kludex merged commit b8139f9 into master Sep 25, 2024
6 checks passed
@Kludex Kludex deleted the consider-chunk-size-on-multiple-ranges branch September 25, 2024 07:16
nixroxursox pushed a commit to nixroxursox/starlette that referenced this pull request Sep 30, 2024
…ode#2703)

* Take in consideration the `FileResponse.chunk_size` on multiple ranges

* Update starlette/responses.py

* Update starlette/responses.py

* Update starlette/responses.py

Co-authored-by: Frost Ming <[email protected]>

---------

Co-authored-by: Frost Ming <[email protected]>
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 this pull request may close these issues.

3 participants