Skip to content

Commit

Permalink
Merge branch 'master' into improve-types/types-file
Browse files Browse the repository at this point in the history
  • Loading branch information
TechNiick committed Apr 9, 2024
2 parents c3bfe08 + 4e453ce commit 807e8a8
Show file tree
Hide file tree
Showing 5 changed files with 38 additions and 4 deletions.
3 changes: 2 additions & 1 deletion docs/middleware.md
Expand Up @@ -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)
Expand All @@ -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.

Expand Down
13 changes: 13 additions & 0 deletions 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
Expand Down
2 changes: 0 additions & 2 deletions scripts/check
Expand Up @@ -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
2 changes: 1 addition & 1 deletion starlette/__init__.py
@@ -1 +1 @@
__version__ = "0.37.1"
__version__ = "0.37.2"
22 changes: 22 additions & 0 deletions tests/test_datastructures.py
Expand Up @@ -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")
Expand All @@ -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:
Expand Down Expand Up @@ -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")])
Expand Down

0 comments on commit 807e8a8

Please sign in to comment.