Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions asgiref/typing.py
Original file line number Diff line number Diff line change
Expand Up @@ -140,6 +140,8 @@ class HTTPResponseTrailersEvent(TypedDict):
class HTTPResponsePathsendEvent(TypedDict):
type: Literal["http.response.pathsend"]
path: str
offset: NotRequired[int]
count: NotRequired[int]


class HTTPServerPushEvent(TypedDict):
Expand Down
24 changes: 24 additions & 0 deletions docs/extensions.rst
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,22 @@ ASGI servers that implement this extension will provide
},
}

Servers that support the ``offset`` and ``count`` parameters for range
requests must advertise this capability via::

"scope": {
...
"extensions": {
"http.response.pathsend": {
"ranges": True,
},
},
}

Applications should check for the presence of ``ranges`` before using
``offset`` and ``count`` parameters. Servers that advertise
``"ranges": True`` must handle these parameters correctly.

The ASGI framework can initiate a path-send by sending a message with
the following keys. This message can be sent at any time after the
*Response Start* message, and cannot be mixed with ``http.response.body``.
Expand All @@ -160,6 +176,14 @@ Keys:
* ``path`` (*Unicode string*): The string representation of the absolute
file path to be sent by the server, platform specific.

* ``offset`` (*int*): Optional. If this value exists, it will specify
the offset at which the server starts to read data from ``path``.
Otherwise, it will be read from the beginning of the file.

* ``count`` (*int*): Optional. ``count`` is the number of bytes to
copy from the file. If omitted, the file will be read from the
offset (or beginning) until its end.

The ASGI application itself is responsible to send the relevant headers
in the *Response Start* message, like the ``Content-Type`` and
``Content-Length`` headers for the file to be sent.
Expand Down