From 65bfd74307f593505aaa4c399f73e4d90cd8aa78 Mon Sep 17 00:00:00 2001 From: Marcelo Trylesinski Date: Mon, 23 Sep 2024 08:13:56 +0200 Subject: [PATCH] Version 0.39.0 (#2699) --- docs/release-notes.md | 7 +++++++ docs/responses.md | 12 ++++++++---- starlette/__init__.py | 2 +- starlette/responses.py | 3 +-- 4 files changed, 17 insertions(+), 7 deletions(-) diff --git a/docs/release-notes.md b/docs/release-notes.md index cd71697d2..f7c737974 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -3,6 +3,13 @@ hide: navigation toc_depth: 2 --- +## 0.39.0 (September 23, 2024) + +#### Added + +* Add support for [HTTP Range](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests) to + `FileResponse` [#2697](https://github.com/encode/starlette/pull/2697). + ## 0.38.6 (September 22, 2024) #### Fixed diff --git a/docs/responses.md b/docs/responses.md index ae48d2f14..a19f77018 100644 --- a/docs/responses.md +++ b/docs/responses.md @@ -183,12 +183,16 @@ async def app(scope, receive, send): await response(scope, receive, send) ``` +File responses also supports [HTTP range requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests). + +The `Accept-Ranges: bytes` header will be included in the response if the file exists. For now, only the `bytes` +range unit is supported. + +If the request includes a `Range` header, and the file exists, the response will be a `206 Partial Content` response +with the requested range of bytes. If the range is invalid, the response will be a `416 Range Not Satisfiable` response. + ## Third party responses #### [EventSourceResponse](https://github.com/sysid/sse-starlette) A response class that implements [Server-Sent Events](https://html.spec.whatwg.org/multipage/server-sent-events.html). It enables event streaming from the server to the client without the complexity of websockets. - -#### [baize.asgi.FileResponse](https://baize.aber.sh/asgi#fileresponse) - -As a smooth replacement for Starlette [`FileResponse`](https://www.starlette.io/responses/#fileresponse), it will automatically handle [Head method](https://developer.mozilla.org/en-US/docs/Web/HTTP/Methods/HEAD) and [Range requests](https://developer.mozilla.org/en-US/docs/Web/HTTP/Range_requests). diff --git a/starlette/__init__.py b/starlette/__init__.py index f2664a769..e72781a79 100644 --- a/starlette/__init__.py +++ b/starlette/__init__.py @@ -1 +1 @@ -__version__ = "0.38.6" +__version__ = "0.39.0" diff --git a/starlette/responses.py b/starlette/responses.py index cf8d6e6b4..b73e04a40 100644 --- a/starlette/responses.py +++ b/starlette/responses.py @@ -12,7 +12,6 @@ from functools import partial from mimetypes import guess_type from random import choices as random_choices -from typing import Mapping from urllib.parse import quote import anyio @@ -280,7 +279,7 @@ def __init__( self, path: str | os.PathLike[str], status_code: int = 200, - headers: Mapping[str, str] | None = None, + headers: typing.Mapping[str, str] | None = None, media_type: str | None = None, background: BackgroundTask | None = None, filename: str | None = None,