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

Byte Range request beyond end of file #2991

Open
keniwhat opened this issue Mar 30, 2023 · 7 comments
Open

Byte Range request beyond end of file #2991

keniwhat opened this issue Mar 30, 2023 · 7 comments
Labels
bug Something isn't working

Comments

@keniwhat
Copy link

Describe the bug

A byte range request beyond end of file returns HTTP Status 400 (Bad Request).

To Reproduce

Steps to reproduce the behavior:

  1. Create vapor server with FileMiddlware.
  2. Send a byte-range request that goes past end-of-file.
  3. You will get a 400 error.

Expected behavior

While Vapor behaviour is technically correct, other servers (apache, AWS - apache or nginx?) are more forgiving, returning the remaining bytes in the file. As a consequence of this historical leniency, HTTP client code exists (open source) that technically have this bug, but will work with other servers but not Vapor.

Can vapor be made more lenient in this respect?
That is, if a byte range request goes past end of file, just return bytes to end of file.

Environment

  • Vapor Framework version: 4.67.4
  • Vapor Toolbox version: N/A
  • OS version: Any

Additional context

I have patched vapor to affect this fix and it my client code works now with vapor.

@keniwhat keniwhat added the bug Something isn't working label Mar 30, 2023
@0xTim
Copy link
Member

0xTim commented Apr 11, 2023

@keniwhat I think this makes sense to make Vapor a little less strict. The only thing that would make me hesitant would be the RFC saying we MUST NOT accept invalid range requests. If you can link to the IETF RFC for range stuff in the PR where I'm sure it says we only SHOULD accept valid range requests that would be great

@keniwhat
Copy link
Author

As per this document (https://httpwg.org/specs/rfc7233.html), Section 2.1, the HTTP server should treat a range request beyond end-of-file as being upto end-of-file. Screenshot attached:

Screenshot 2023-04-11 at 13 32 57

@0xTim
Copy link
Member

0xTim commented Apr 11, 2023

@keniwhat even more reason to make Vapor more flexible then. Very happy to accept a PR 👍

@linus-hologram
Copy link
Contributor

@0xTim is this still a thing? If so I'd look into it :)

@linus-hologram
Copy link
Contributor

@0xTim any update on this?

@keniwhat
Copy link
Author

keniwhat commented Apr 8, 2024

I made the changes to the code and test as requested but it has not been merged. Let me know what you need from me to get this onto the main vapor/vapor project.

@bplattenburg
Copy link

@linus-hologram @keniwhat It looks like this is tracked in #2997?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

4 participants