Commit Graph

465 Commits

Author SHA1 Message Date
Victor Westerhuis ca1f45dc12
Use ETag from headers when parsing If-Range in FileResponse (#2761) 2024-12-03 08:07:22 +01:00
涵曦 eee4cdcb9a
Fix: Resolve the issue where the directory itself being a symlink does not work. (#2711) 2024-12-01 17:46:16 +01:00
Sean Chen 35dae138a0
test: add tests in `test_routing` (#2676)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-11-30 09:58:59 +00:00
Marcelo Trylesinski 5ccbc62175
Pin httpx in `full` extra (#2773) 2024-11-30 10:53:55 +01:00
Eugene Toder 13d0c1fbcd
Make _MiddlewareFactory compatible with Callable (#2768) 2024-11-26 01:28:34 -06:00
Marcelo Trylesinski 7d586f7e39
Support for `send` client disconnect to HTTP (#2732) 2024-11-18 21:56:13 +01:00
Hao Guan 9dc9d2e929
fix(testclient): exclude query sting from `raw_path` (#2716)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-11-18 20:28:43 +01:00
Yurii Karabas 427a8dcf35
Fix issue with middleware args passing (#2752) 2024-11-14 17:34:22 -06:00
Marcelo Trylesinski 99b6938363
Allow to raise `HTTPException` before `websocket.accept()` (#2725)
* Allow to raise `HTTPException` before `websocket.accept()`

* move <<

* Add documentation
2024-10-15 09:50:49 +02:00
Marcelo Trylesinski fd038f3070
Merge commit from fork 2024-10-15 08:40:51 +02:00
Joel Sleppy fe46d99d92
Support `request.url_for` when only "app" scope is avaialable (#2672)
* Support request.url_for in BaseMiddleware

* Move test to test_requests

* Call the endpoint properly

* fix test

* order the type hint

---------

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-09-29 09:40:23 +00:00
Marcelo Trylesinski 1a6018e08a
Support python-multipart 0.0.12 (#2708) 2024-09-29 10:28:34 +02:00
Trim21 075efd0c5c
generate boundary with token_hex (#2702)
* generate boundary with token_hex

* generate boundary with token_hex

* fix

* boundary size

* Update starlette/responses.py

---------

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-09-25 11:27:55 +00:00
Marcelo Trylesinski b8139f9fe3
Consider `FileResponse.chunk_size` when handling multiple ranges (#2703)
* Take in consideration the `FileResponse.chunk_size` on multiple ranges

* Update starlette/responses.py

* Update starlette/responses.py

* Update starlette/responses.py

Co-authored-by: Frost Ming <mianghong@gmail.com>

---------

Co-authored-by: Frost Ming <mianghong@gmail.com>
2024-09-25 09:16:08 +02:00
Orenoid 4fbf766b3e
test: add tests in `test_requests` (#2677)
* test: add tests in test_requests

* test: add test for Request.close method

* fix: typo

* test: ignore conditional branch in coverage report and remove unnecessary test

* test: pragma no branch

---------

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-09-23 18:38:19 +00:00
Trim21 d289ac7e8d
perf: stop use `re` on `get_route_path` (#2701)
* perf: stop use re on get_route_path

* add test
2024-09-23 20:23:34 +02:00
Marcelo Trylesinski 69ed26a859
Add support for HTTP Range to `FileResponse` (#2697)
* Add support for HTTP Range to `FileResponse`

* Remove pragmas

* Single line
2024-09-23 09:20:21 +08:00
Adrian Garcia Badaracco 53f9dc02be
Fix `BackgroundTasks` with `BaseHTTPMiddleware` (#2688)
* Streaming response early disconnect mode

* Fix BackgroundTasks with BaseHTTPMiddleware

* move comment

* initialize field

---------

Co-authored-by: Dmitry Maliuga <dmaliuga@fireworks.ai>
2024-09-07 13:42:54 +01:00
Gabriel Figueiredo 1131b3cbcd
Ensure accurate `root_path` removal in `get_route_path` function (#2600)
* fix: regex inside function get_route_path to remove root_path

* fix: apply format ruff

* fix: mypy

---------

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-09-01 17:12:43 +02:00
Marcelo Trylesinski b9db010d49
Set `line-length` to 120 on Ruff (#2679)
* Set `line-length` to 120 on Ruff

* Add links to selected rules

* Remove empty strings

* Fix more stuff
2024-09-01 15:11:01 +02:00
Adrian Garcia Badaracco d771bb7a5e
Don't poll for disconnects in BaseHTTPMiddleware via StreamingResponse (#2620)
* Don't poll for disconnects in BaseHTTPMiddleware via StreamingResponse

Fixes #2516

* add test

* fmt

* Update tests/middleware/test_base.py

Co-authored-by: Mikkel Duif <mikkel@duifs.dk>

* add test for line now missing coverage

* more coverage, fix test

* add comment

* fmt

* tweak test

* fix

* fix coverage

* relint

---------

Co-authored-by: Mikkel Duif <mikkel@duifs.dk>
2024-09-01 09:04:50 +02:00
Orenoid e46165a1ca
Add tests to `test_responses` (#2656)
* test: add test cases for uncovered branches in starlette.responses

* chore: fix format issue

* Update test

* Remove unused import

* Update tmpdir to tmp_path

---------

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-08-06 07:14:59 +00:00
Scirlat Danut 78fcd54c07
Create types module inside tests (#2502)
* Create types module inside tests

* Apply suggestions from code review

* Apply suggestions from code review

* Fix check errors

* Change testclientfactory due to autotest

* No cover fix

* Apply suggestions from code review

* Skip code coverage for TestClientFactory protocol

* Apply suggestions from code review

* Small improvements

* Lint

* Fix everything

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-07-27 03:31:16 -06:00
dependabot[bot] 296cab922a
Bump the python-packages group with 13 updates (#2632)
* Bump the python-packages group with 13 updates

Bumps the python-packages group with 13 updates:

| Package | From | To |
| --- | --- | --- |
| [anyio](https://github.com/agronholm/anyio) | `4.3.0` | `4.4.0` |
| [coverage](https://github.com/nedbat/coveragepy) | `7.4.3` | `7.5.4` |
| [importlib-metadata](https://github.com/python/importlib_metadata) | `7.0.1` | `8.0.0` |
| [mypy](https://github.com/python/mypy) | `1.8.0` | `1.10.1` |
| [ruff](https://github.com/astral-sh/ruff) | `0.1.15` | `0.5.0` |
| [typing-extensions](https://github.com/python/typing_extensions) | `4.10.0` | `4.12.2` |
| [types-pyyaml](https://github.com/python/typeshed) | `6.0.12.12` | `6.0.12.20240311` |
| [pytest](https://github.com/pytest-dev/pytest) | `8.0.2` | `8.2.2` |
| [trio](https://github.com/python-trio/trio) | `0.24.0` | `0.25.1` |
| [mkdocs](https://github.com/mkdocs/mkdocs) | `1.5.3` | `1.6.0` |
| [mkdocs-material](https://github.com/squidfunk/mkdocs-material) | `9.5.12` | `9.5.27` |
| [build](https://github.com/pypa/build) | `1.1.1` | `1.2.1` |
| [twine](https://github.com/pypa/twine) | `5.0.0` | `5.1.1` |


Updates `anyio` from 4.3.0 to 4.4.0
- [Release notes](https://github.com/agronholm/anyio/releases)
- [Changelog](https://github.com/agronholm/anyio/blob/master/docs/versionhistory.rst)
- [Commits](https://github.com/agronholm/anyio/compare/4.3.0...4.4.0)

Updates `coverage` from 7.4.3 to 7.5.4
- [Release notes](https://github.com/nedbat/coveragepy/releases)
- [Changelog](https://github.com/nedbat/coveragepy/blob/master/CHANGES.rst)
- [Commits](https://github.com/nedbat/coveragepy/compare/7.4.3...7.5.4)

Updates `importlib-metadata` from 7.0.1 to 8.0.0
- [Release notes](https://github.com/python/importlib_metadata/releases)
- [Changelog](https://github.com/python/importlib_metadata/blob/main/NEWS.rst)
- [Commits](https://github.com/python/importlib_metadata/compare/v7.0.1...v8.0.0)

Updates `mypy` from 1.8.0 to 1.10.1
- [Changelog](https://github.com/python/mypy/blob/master/CHANGELOG.md)
- [Commits](https://github.com/python/mypy/compare/v1.8.0...v1.10.1)

Updates `ruff` from 0.1.15 to 0.5.0
- [Release notes](https://github.com/astral-sh/ruff/releases)
- [Changelog](https://github.com/astral-sh/ruff/blob/main/CHANGELOG.md)
- [Commits](https://github.com/astral-sh/ruff/compare/v0.1.15...0.5.0)

Updates `typing-extensions` from 4.10.0 to 4.12.2
- [Release notes](https://github.com/python/typing_extensions/releases)
- [Changelog](https://github.com/python/typing_extensions/blob/main/CHANGELOG.md)
- [Commits](https://github.com/python/typing_extensions/compare/4.10.0...4.12.2)

Updates `types-pyyaml` from 6.0.12.12 to 6.0.12.20240311
- [Commits](https://github.com/python/typeshed/commits)

Updates `pytest` from 8.0.2 to 8.2.2
- [Release notes](https://github.com/pytest-dev/pytest/releases)
- [Changelog](https://github.com/pytest-dev/pytest/blob/main/CHANGELOG.rst)
- [Commits](https://github.com/pytest-dev/pytest/compare/8.0.2...8.2.2)

Updates `trio` from 0.24.0 to 0.25.1
- [Release notes](https://github.com/python-trio/trio/releases)
- [Commits](https://github.com/python-trio/trio/compare/v0.24.0...v0.25.1)

Updates `mkdocs` from 1.5.3 to 1.6.0
- [Release notes](https://github.com/mkdocs/mkdocs/releases)
- [Commits](https://github.com/mkdocs/mkdocs/compare/1.5.3...1.6.0)

Updates `mkdocs-material` from 9.5.12 to 9.5.27
- [Release notes](https://github.com/squidfunk/mkdocs-material/releases)
- [Changelog](https://github.com/squidfunk/mkdocs-material/blob/master/CHANGELOG)
- [Commits](https://github.com/squidfunk/mkdocs-material/compare/9.5.12...9.5.27)

Updates `build` from 1.1.1 to 1.2.1
- [Release notes](https://github.com/pypa/build/releases)
- [Changelog](https://github.com/pypa/build/blob/main/CHANGELOG.rst)
- [Commits](https://github.com/pypa/build/compare/1.1.1...1.2.1)

Updates `twine` from 5.0.0 to 5.1.1
- [Release notes](https://github.com/pypa/twine/releases)
- [Changelog](https://github.com/pypa/twine/blob/main/docs/changelog.rst)
- [Commits](https://github.com/pypa/twine/compare/5.0.0...v5.1.1)

---
updated-dependencies:
- dependency-name: anyio
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: python-packages
- dependency-name: coverage
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: python-packages
- dependency-name: importlib-metadata
  dependency-type: direct:production
  update-type: version-update:semver-major
  dependency-group: python-packages
- dependency-name: mypy
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: python-packages
- dependency-name: ruff
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: python-packages
- dependency-name: typing-extensions
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: python-packages
- dependency-name: types-pyyaml
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: python-packages
- dependency-name: pytest
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: python-packages
- dependency-name: trio
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: python-packages
- dependency-name: mkdocs
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: python-packages
- dependency-name: mkdocs-material
  dependency-type: direct:production
  update-type: version-update:semver-patch
  dependency-group: python-packages
- dependency-name: build
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: python-packages
- dependency-name: twine
  dependency-type: direct:production
  update-type: version-update:semver-minor
  dependency-group: python-packages
...

Signed-off-by: dependabot[bot] <support@github.com>

* Add all changes needed for bump

* Ignore ResourceWarning

---------

Signed-off-by: dependabot[bot] <support@github.com>
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-07-27 03:03:46 -06:00
Giovanni Barillari 67f473d4a3
Revert "Add support for ASGI `pathsend` extension" (#2649)
This reverts commit 7936e86f0a.
2024-07-23 04:10:14 -06:00
Godot 5f57ef4eb1
test: refine the test of client disconnection after reading request body (#2639)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-07-20 09:06:30 +00:00
Adrian Garcia Badaracco d1b38037e7
Allow use of `memoryview` with `Response` (#2577) 2024-06-01 13:12:34 +00:00
Jeremy Epstein 4f16aedc0f
Send 404 instead of 500 when filename requested is too long on `StaticFiles` (#2583)
* Make "Filename too long" return 404 not 500

* Simplify code source

* Correct comment

---------

Co-authored-by: Jeremy Epstein <jeremy.epstein@seertechsolutions.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-06-01 13:07:03 +00:00
Bas Schoenmaeckers 9fd3eccef1
Allow returning memoryview in StreamingResponse (#2576) 2024-04-22 12:15:24 -05:00
Pierre Delagrave 9cf26eebd1
Fail fast on invalid `Jinja2Template` instantiation parameters (#2568)
Calling `Jinja2Template()` with both `directory` and `env` shouldn't be allowed. When both parameters were used, the passed `env` was silently ignored in favor of creating a new one with the provided `directory` and the deprecated `env_options`.
2024-04-20 07:54:26 +00:00
Scirlat Danut 2e504fd2b7
Add tests to `test_datastructure` (#2505)
* Add tests to test_datastructure

* Update tests

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-03-24 17:19:36 +00:00
Amin Alaee 39dccd9112
Revert "Turn `scope["client"]` to `None` on `TestClient` (#2377)" (#2525)
* Revert "Turn `scope["client"]` to `None` on `TestClient` (#2377)"

This reverts commit 483849a466.

* format

* Add type hints

---------

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-29 05:55:04 -07:00
Marcelo Trylesinski bd77d7d9f0
Enforce `__future__.annotations` (#2483) 2024-02-29 10:16:42 +00:00
Scirlat Danut ac7e643984
Add type hints to `test_responses.py` (#2488)
* Add type hints to test_responses.py

* Update tests/test_responses.py

* Linter fix

* Apply suggestions from code review

* Apply suggestions from code review

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-09 09:29:28 +00:00
Scirlat Danut 3f380381d2
Add type hints to `test_testclient.py` (#2493)
* Add type hints to test_testclient.py

* Fix check errors

* Apply suggestions from code review

* Use ASGIInstance instead

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-09 09:13:38 +00:00
Scirlat Danut eaee85be84
Add type hints to `test_templates.py` (#2492)
* Add type hints to test_templates.py

* Remove any

* nitpick

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-09 09:07:45 +00:00
Scirlat Danut db5247974a
Add type hints to `test_staticfiles.py` (#2491)
* Add type hints to test_staticfiles.py

* Remove any

* Remove ParamSpec

* Remove useless conditional

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-09 08:58:52 +00:00
Scirlat Danut 9576eac076
Add type hints to `test_routing.py` (#2489)
* Add type hints to test_routing.py

* Apply suggestions from code review

* Fix check errors

* Apply suggestions from code review

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-07 20:17:51 +00:00
Scirlat Danut 179d934b55
Add type hints to `test_websockets.py` (#2494)
Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-07 19:56:21 +00:00
Scirlat Danut 7cc2ec05bd
Add type hints to `test_schemas.py` (#2490)
Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
2024-02-07 18:47:23 +00:00
Scirlat Danut c811ebd28e
Add type hints to `test_formparsers.py` (#2480)
* added type annotations to test_formparsers.py

* Apply suggestions from code review

* Apply suggestions from code review

* Apply suggestions from code review

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-06 22:01:44 +00:00
Mathias Hauser 7ec763c48b
Warn instead of exception for missing env file (#2485) 2024-02-06 14:58:35 -07:00
Scirlat Danut 0e4da0aea2
Add type hints to `test_authentication.py` (#2472)
* added type annotations to test_authentication.py

* fixed types

* Apply suggestions from code review

* Fix linting

* Fix linting

* Apply suggestions from code review

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-06 20:47:45 +00:00
Scirlat Danut 11b7ae7365
Add type hints to `test_applications.py` (#2471)
* added type annotations to test_applications.py

* requested changes

* Apply suggestions from code review

* Apply suggestions from code review

* Update tests/test_applications.py

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-06 20:30:47 +00:00
Scirlat Danut 8c222960ba
Add type hints to `test_requests.py` (#2481)
* added type annotations to test_requests.py

* requested changes

* indentations

* typos

* typos

* Apply suggestions from code review

* Apply suggestions from code review

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-06 13:18:43 -07:00
Scirlat Danut ee3cdfd5dc
Add type hints to `test_gzip.py` (#2464)
* added type annotations to test_gzip.py

* Apply suggestions from code review

* Apply suggestions from code review

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-05 10:46:34 +00:00
Scirlat Danut 52531565cc
Added type annotations to test_endpoints.py (#2478)
* added type annotations to test_endpoints.py

* Apply suggestions from code review

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-04 14:06:00 -07:00
Scirlat Danut c158ef45be
Added type annotations to test_error.py (#2462)
* added type annotations to test_error.py

* Apply suggestions from code review

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-04 20:54:16 +00:00
Kristján Valur Jónsson 93e74a4d2f
Support the WebSocket Denial Response ASGI extension (#2041)
* supply asgi_extensions to TestClient

* Add WebSocket.send_response()

* Add response support for WebSocket testclient

* fix test for filesystem line-endings

* lintint

* support websocket.http.response extension by default

* Improve coverate

* Apply suggestions from code review

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* Undo unrelated change

* fix incorrect error message

* Update starlette/websockets.py

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* formatting

* Re-introduce close-code and close-reason to WebSocketReject

* Make sure the "websocket.connect" message is received in tests

* Deliver a websocket.disconnect message to the app even if it closes/rejects itself.

* Add test for filling out missing `websocket.disconnect` code

* Add rejection headers.  Expand tests.

* Fix types, headers in message are `bytes` tuples.

* Minimal WebSocket Denial Response implementation

* Revert "Minimal WebSocket Denial Response implementation"

This reverts commit 7af10ddcfa5423c18953cf5d1317cb5aa30a014c.

* Rename to send_denial_response and update documentation

* Remove the app_disconnect_msg.  This can be added later in a separate PR

* Remove status code 1005 from this PR

* Assume that the application has tested for the extension before sending websocket.http.response.start

* Rename WebSocketReject to WebSocketDenialResponse

* Remove code and status from WebSocketDenialResponse.
Just send a regular WebSocketDisconnect even when connection is rejected with close()

* Raise an exception if attempting to send a http response and server does not support it.

* WebSocketDenialClose and WebSocketDenialResponse
These are both instances of WebSocketDenial.

* Update starlette/testclient.py

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* Revert "WebSocketDenialClose and WebSocketDenialResponse"

This reverts commit 71b76e3f1c.

* Rename parameters, member variables

* Use httpx.Response as the base for WebSocketDenialResponse.

* Apply suggestions from code review

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>

* Update sanity check message

* Remove un-needed function

* Expand error message test regex

* Add type hings to test methods

* Add doc string to test.

* Fix mypy complaining about mismatching parent methods.

* nitpick & remove test

* Simplify the documentation

* Update starlette/testclient.py

* Update starlette/testclient.py

* Remove an unnecessary test

* there is no special "close because of rejection" in the testclient anymore.

---------

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-04 20:16:10 +00:00
Scirlat Danut 043c800210
Added type annotations to test_convertors.py (#2476)
* added type annotations to test_convertors.py

* Apply suggestions from code review

---------

Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-04 18:39:34 +00:00