diff --git a/docs/middleware.md b/docs/middleware.md index 759c86d70e..dfe0a70d7b 100644 --- a/docs/middleware.md +++ b/docs/middleware.md @@ -185,7 +185,7 @@ from starlette.middleware.gzip import GZipMiddleware routes = ... middleware = [ - Middleware(GZipMiddleware, minimum_size=1000) + Middleware(GZipMiddleware, minimum_size=1000, compresslevel=9) ] app = Starlette(routes=routes, middleware=middleware) @@ -194,6 +194,7 @@ app = Starlette(routes=routes, middleware=middleware) The following arguments are supported: * `minimum_size` - Do not GZip responses that are smaller than this minimum size in bytes. Defaults to `500`. +* `compresslevel` - Used during GZip compression. It is an integer ranging from 1 to 9. Defaults to `9`. Lower value results in faster compression but larger file sizes, while higher value results in slower compression but smaller file sizes. The middleware won't GZip responses that already have a `Content-Encoding` set, to prevent them from being encoded twice. diff --git a/docs/release-notes.md b/docs/release-notes.md index b17fabef40..b5e2124c5a 100644 --- a/docs/release-notes.md +++ b/docs/release-notes.md @@ -1,3 +1,16 @@ +## 0.37.2 + +March 5, 2024 + +#### Added + +* Add `bytes` to `_RequestData` type [#2510](https://github.com/encode/starlette/pull/2510). + +#### Fixed + +* Revert "Turn `scope["client"]` to `None` on `TestClient` (#2377)" [#2525](https://github.com/encode/starlette/pull/2525). +* Remove deprecated `app` argument passed to `httpx.Client` on the `TestClient` [#2526](https://github.com/encode/starlette/pull/2526). + ## 0.37.1 February 9, 2024 diff --git a/scripts/check b/scripts/check index 3e8f057846..3aa439a425 100755 --- a/scripts/check +++ b/scripts/check @@ -10,7 +10,5 @@ set -x ./scripts/sync-version ${PREFIX}ruff format --check --diff $SOURCE_FILES -# TODO: Use `[[tool.mypy.overrides]]` on the `pyproject.toml` when the mypy issue is solved: -# github.com/python/mypy/issues/10045. Check github.com/encode/starlette/pull/2180 for more info. ${PREFIX}mypy $SOURCE_FILES ${PREFIX}ruff check $SOURCE_FILES diff --git a/starlette/__init__.py b/starlette/__init__.py index 04b7c866d1..4a2dd331e8 100644 --- a/starlette/__init__.py +++ b/starlette/__init__.py @@ -1 +1 @@ -__version__ = "0.37.1" +__version__ = "0.37.2" diff --git a/tests/test_datastructures.py b/tests/test_datastructures.py index b7d6725d45..a6bca6ef6d 100644 --- a/tests/test_datastructures.py +++ b/tests/test_datastructures.py @@ -58,6 +58,9 @@ def test_url() -> None: url = URL("http://u:p@host:80") assert url.replace(port=88) == URL("http://u:p@host:88") + url = URL("http://host:80") + assert url.replace(username="u") == URL("http://u@host:80") + def test_url_query_params() -> None: u = URL("https://example.org/path/?page=3") @@ -70,6 +73,10 @@ def test_url_query_params() -> None: assert str(u) == "https://example.org/path/?order=name" u = u.remove_query_params("order") assert str(u) == "https://example.org/path/" + u = u.include_query_params(page=4, search="testing") + assert str(u) == "https://example.org/path/?page=4&search=testing" + u = u.remove_query_params(["page", "search"]) + assert str(u) == "https://example.org/path/" def test_hidden_password() -> None: @@ -138,6 +145,21 @@ def test_url_from_scope() -> None: assert u == "https://example.org/path/to/somewhere?abc=123" assert repr(u) == "URL('https://example.org/path/to/somewhere?abc=123')" + u = URL( + scope={ + "scheme": "http", + "path": "/some/path", + "query_string": b"query=string", + "headers": [ + (b"content-type", b"text/html"), + (b"host", b"example.com:8000"), + (b"accept", b"text/html"), + ], + } + ) + assert u == "http://example.com:8000/some/path?query=string" + assert repr(u) == "URL('http://example.com:8000/some/path?query=string')" + def test_headers() -> None: h = Headers(raw=[(b"a", b"123"), (b"a", b"456"), (b"b", b"789")])