-
Notifications
You must be signed in to change notification settings - Fork 232
Added offset and count parameters to pathsend extension #538
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
base: main
Are you sure you want to change the base?
Added offset and count parameters to pathsend extension #538
Conversation
a45b794 to
c62c6bb
Compare
This extends the http.response.pathsend extension to support partial
file sends by adding optional offset and count parameters, enabling
HTTP Range request support (RFC 7233) and efficient seeking in large
media files.
The parameters mirror the existing http.response.zerocopysend API:
- offset: byte position to start reading from (default: beginning)
- count: number of bytes to send (default: to end of file)
This allows ASGI frameworks to implement range requests without
handling file descriptors directly, offloading the operation to
the server while maintaining pathsend's simpler API.
Capability Signaling:
Servers that support offset and count parameters MUST advertise this
by setting {"ranges": True} in the pathsend extension scope dict.
Applications should check for this flag before using these parameters.
This provides a clear upgrade path from basic pathsend to range-capable
pathsend without ambiguity.
The application remains responsible for:
- Checking the "ranges" capability flag
- Parsing Range request headers
- Setting appropriate response headers (Content-Range, Content-Length,
Accept-Ranges, status 206)
Fixes django#469
Related: emmett-framework/granian#157
c62c6bb to
e59e343
Compare
|
Cc @Kludex |
|
cc @gi0baro |
|
My 2 cents: the 2 keys vs single tuple key won't really change that much, the latter just simplify the message parsing on the server side. I would say the |
I think I'm sold that offset/count aren't the greatest or most intuitive; they were probably originally chosen to match
I do think it's a little confusing between the two extensions, but my reading of the linked threads is that zerocopysend is a bit "dead", so it's probably not worth matching?
I do like the idea that all of the fields are prefixed similarly ( Here's some more alternatives:
Or any permutations of the above, including with the Anyone else have strong opinions that wants to weigh in? My personal preference is |
Background Context
I read #469 and discussed with @gi0baro in this thread emmett-framework/granian#157 about trying to get this as part of the ASGI spec. The implementation here is just a straight copy of the discussion in the relevant thread. It didn't seem that people had too much of a disagreement of what it'd look like, and if we did we could hash it out in this PR.
Links:
offsetandcountto Path Send #469: Issue describing potential improvements to pathsend (what this PR implements)(draft)
This extends the
http.response.pathsendextension to support partial file sends by adding optional offset and count parameters, enabling HTTP Range request support.The parameters mirror the existing
http.response.zerocopysendAPI:offset: byte position to start reading from (default: beginning)count: number of bytes to send (default: to end of file)This allows ASGI frameworks to implement range requests without loading the bytes themselves, offloading the operation to the server.
Servers may advertise range support capability by setting {"ranges": True} in the extension scope dict, allowing frameworks to detect this capability.
The application remains responsible for setting appropriate headers (Content-Range, Content-Length, Accept-Ranges) in the response.
Fixes #469
Implementation
This original comment also proposed an alternative that uses
rangeinstead of offset+count. I don't really have strong opinions one way or another about which we use, but I see the trade-offs as:rangeis just one key, and its explicit about the start/end bytes. If we were to do this, we'd need to make a decision about being inclusive/exclusive with the ending byte (I think exclusive ending byte is common in most situations, but http range GETs are inclusive, so we should likely match that: docs)I'm also in the process of a branch on granian where I'm going to do a quick example implementation just to give an example. I'll likely use granian + starlette to showcase what this extended pathsend could look like
First time contributing to and submitting a PR to asgiref, so please feel free to badger me about bits that I'm missing!