Skip to content

Commit c62c6bb

Browse files
Added offset and count parameters to pathsend extension
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. Like zerocopysend, these parameters are optional for applications (with sensible defaults), but servers that advertise pathsend support are expected to handle all documented parameters including offset and count. The application remains responsible for setting appropriate headers (Content-Range, Content-Length, Accept-Ranges) in the response. Fixes #469 Related: emmett-framework/granian#157
1 parent b7b15b2 commit c62c6bb

File tree

2 files changed

+10
-0
lines changed

2 files changed

+10
-0
lines changed

asgiref/typing.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,8 @@ class HTTPResponseTrailersEvent(TypedDict):
140140
class HTTPResponsePathsendEvent(TypedDict):
141141
type: Literal["http.response.pathsend"]
142142
path: str
143+
offset: NotRequired[int]
144+
count: NotRequired[int]
143145

144146

145147
class HTTPServerPushEvent(TypedDict):

docs/extensions.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,14 @@ Keys:
160160
* ``path`` (*Unicode string*): The string representation of the absolute
161161
file path to be sent by the server, platform specific.
162162

163+
* ``offset`` (*int*): Optional. If this value exists, it will specify
164+
the offset at which the server starts to read data from ``path``.
165+
Otherwise, it will be read from the beginning of the file.
166+
167+
* ``count`` (*int*): Optional. ``count`` is the number of bytes to
168+
copy from the file. If omitted, the file will be read from the
169+
offset (or beginning) until its end.
170+
163171
The ASGI application itself is responsible to send the relevant headers
164172
in the *Response Start* message, like the ``Content-Type`` and
165173
``Content-Length`` headers for the file to be sent.

0 commit comments

Comments
 (0)