Renan Heckert Leal
c82acf3a03
Remove deprecated `allow_redirects` argument from `TestClient` ( #2808 )
2024-12-25 09:45:38 +01:00
Renan Heckert Leal
f884b6649e
tests: adding `# pragma: no branch` in `middleware/test_base` and `test_routing` ( #2807 )
...
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-12-21 19:11:28 +00:00
Marcelo Trylesinski
5ccbc62175
Pin httpx in `full` extra ( #2773 )
2024-11-30 10:53:55 +01:00
Yurii Karabas
427a8dcf35
Fix issue with middleware args passing ( #2752 )
2024-11-14 17:34:22 -06: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
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
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
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
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
Marcelo Trylesinski
bd77d7d9f0
Enforce `__future__.annotations` ( #2483 )
2024-02-29 10:16:42 +00: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
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
Scirlat Danut
5ab70d8fdf
added type annotations to test_http_redirect.py ( #2465 )
...
Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
2024-02-04 18:30:43 +00:00
Scirlat Danut
a2f2dda8d7
Added type annotations to test_session.py ( #2466 )
...
Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
2024-02-04 17:58:54 +00:00
Scirlat Danut
adf51ea75d
Add type hints to `test_trusted_host.py` ( #2467 )
...
Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
2024-02-04 15:13:48 +00:00
Scirlat Danut
1f466cce11
Add type hints to `test_wsgi.py` ( #2468 )
...
Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
2024-02-04 08:11:13 -07:00
Scirlat Danut
a9af536a07
Add type hints to `test_cors.py` ( #2458 )
...
Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
2024-02-03 13:51:19 -07:00
Scirlat Danut
3434c3d990
Add type hints to `test_base.py` ( #2445 )
...
* added type annotations to test-base.py
* deleted unused imports
* fixed import order
* conditional import
* conditional import TestClient on types.py
* using string literals when importing in types
* added missing imports
* deleted starlette/types, refactored test_base types
* deleted types
---------
Co-authored-by: Scirlat Danut <scirlatdanut@scirlats-mini.lan>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-03 09:54:21 -07:00
Sebastián Ramírez
c3c6314759
♻️ Refactor logic to handle `root_path` to keep compatibility with ASGI and compatibility with other non-Starlette-specific libraries like a2wsgi ( #2400 )
...
* ✨ Add util to get route path from scope
* ♻️ Refactor extracting the local route_path from the scope, and creating the child scope with its own root_pat, this allows sub-apps (e.g. WSGIMiddleware) to know
where it was mounted, and from which path prefix starts the path its sub-app should handle
* ♻️ Refactor datastructures and request to be conformant with the ASGI spec, respecting root_path
* ✅ Add and update tests for root_path with mounted apps that don't know about Starlette internals (e.g. the route_root_path extension scope key that was added in
* ✅ Update test for root_path, TestClient was not requiring paths under a root_path to pass the root_path, which is what clients would have to do if the app is
mounted.
* 🎨 Fix formatting
* 🎨 Remove type ignore
* 🔥 Remove unnecessary comment
* ✨ Update (deprecated) WSGIMiddleware to be compatible with the updated root_path, taking pieces from a2wsgi
* 🎨 Fix types
* ✅ Update test for WSGIMiddleware with root_path
* 🔥 Remove logic/features not in the original (deprecated) WSGIMiddleware
---------
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Aber <me@abersheeran.com>
2024-01-09 12:45:30 +08:00
dependabot[bot]
d28d491a34
Bump ruff from 0.1.6 to 0.1.9 ( #2396 )
...
* Bump ruff from 0.1.6 to 0.1.9
Bumps [ruff](https://github.com/astral-sh/ruff ) from 0.1.6 to 0.1.9.
- [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.6...v0.1.9 )
---
updated-dependencies:
- dependency-name: ruff
dependency-type: direct:production
update-type: version-update:semver-patch
...
Signed-off-by: dependabot[bot] <support@github.com>
* Fix code
---------
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-01-08 08:49:23 +00:00
Paweł Rubin
866a15f79c
Add `*args` to `Middleware` and improve its type hints ( #2381 )
...
Co-authored-by: Paweł Rubin <pawel.rubin@ocado.com>
2023-12-20 22:09:17 +01:00
Marcelo Trylesinski
efa03ebd64
Merge URLs properly on TestClient ( #2376 )
2023-12-16 06:55:20 -07:00
zllvm
e0176007d3
Add `domain` parameter to `SessionMiddleware` ( #2280 )
...
* feat: add domain argument to SessionMiddleware
* docs: keep existing formatting
* fix: add newline at end of file
* fix: comply with formatting
* fix: comply with formatting rules
* fix: set domain default value to empty string
* Make `domain` `Optional[str]`
---------
Co-authored-by: max <max@maxlabs.se>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2023-11-03 12:17:43 +00:00
Jean Hominal
2847df0ba1
Ensure event ordering in test_app_receives_http_disconnect_while_sending_if_discarded ( #2284 )
2023-09-16 19:27:52 -05:00
Alex Grönholm
7349c60a81
Fixed import error when exceptiongroup isn't available ( #2231 )
...
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2023-08-25 20:29:44 +02:00
Alex Grönholm
1a71441ed0
Upgraded to AnyIO 4.0 ( #2211 )
...
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2023-07-23 06:26:35 +00:00
Marcelo Trylesinski
11a3f1227e
Stop `body_stream` in case `more_body=False` ( #2194 )
2023-07-13 01:48:10 -06:00
Adrian Garcia Badaracco
554b9e21f6
Reuse Request's body buffer for call_next in BaseHTTPMiddleware ( #1692 )
2023-06-01 13:57:28 -05:00
Michał Górny
88e9fc1411
Fix test_gzip_ignored_for_responses_with_encoding_set w/ brotli ( #1962 )
...
Closes https://github.com/encode/starlette/pull/1597
2022-11-23 09:02:53 +01:00
kklingenberg
858629f518
Bypass GZipMiddleware when response includes `Content-Encoding` ( #1901 )
...
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2022-10-12 16:15:29 +02:00
Jean Hominal
040d8c86b0
Replace task cancellation in `BaseHTTPMiddleware` with `http.disconnect`+`recv_stream.close` ( #1715 )
...
* replace BaseMiddleware cancellation after request send with closing recv_stream + http.disconnect in receive
fixes #1438
* Add no cover pragma on pytest.fail in tests/middleware/test_base.py
Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
* make http_disconnect_while_sending test more robust in the face of scheduling issues
* Fix issue with running middleware context manager
Reported in https://github.com/encode/starlette/issues/1678#issuecomment-1172916042
Co-authored-by: Adrian Garcia Badaracco <1755071+adriangb@users.noreply.github.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2022-09-24 07:29:08 +02:00
Marcelo Trylesinski
6765502c1e
Replace HTTP client on TestClient from `requests` to `httpx` ( #1376 )
2022-09-06 07:43:32 +02:00
Adrian Garcia Badaracco
dec10cab89
move test from test_base.py to test_routing.py ( #1693 )
2022-06-15 08:22:18 -05:00
Adrian Garcia Badaracco
5a9b41475a
Document interaction of BaseHTTPMiddleware and contextvars ( #1525 )
...
* test: document behavior of ContextVars with BaseHTTPMiddleware
* lint & fix
* add pragma
* Update test_base.py
* Update tests/middleware/test_base.py
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
* fix typo
* try to make comment clearer
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2022-04-24 06:48:50 +02:00
Tom Christie
62428c585d
SessionMiddleware uses an explicit path=..., instead of defaulting to the ASGI 'root_path'. ( #1512 )
2022-02-14 15:05:14 +00:00
Adrian Garcia Badaracco
f68b49408a
Remove deprecated decorators from test_base ( #1493 )
...
* remove deprecated routing and middleware decorators from test_base.py
* remove deprecated routing and middleware decorators from test_base.py
* remove test_middleware_decorator test
* Update tests/middleware/test_base.py
Co-authored-by: Amin Alaee <mohammadamin.alaee@gmail.com>
* add pragma: nocovers
Co-authored-by: Amin Alaee <mohammadamin.alaee@gmail.com>
2022-02-10 18:36:24 +01:00
Amin Alaee
4f97b25376
Remove routing decorators in test_trusted_hosts.py ( #1494 )
2022-02-10 10:31:49 +01:00
Amin Alaee
6a655721e5
Remove routing decorators in test_session.py ( #1495 )
2022-02-10 10:29:31 +01:00
Amin Alaee
e601ffd57a
Remove routing decorators in test_cors.py ( #1498 )
2022-02-10 10:27:30 +01:00
Amin Alaee
f3403d2404
Remove routing decorators in test_gzip.py ( #1497 )
2022-02-10 10:25:00 +01:00
Amin Alaee
71e1444420
Remove routing decorators in test_https_redirect.py ( #1496 )
2022-02-10 10:22:54 +01:00
Amin Alaee
aa38ce4032
Remove routing decorators in `middleware/test_base.py` ( #1488 )
...
* Remove routing decorators in
* Update test_base.py middleware
2022-02-09 13:59:10 +00:00
Aviram Hassan
400e240f84
Make error handler run always ( #761 )
...
* Error handler call always
* Add tests
* Add docs
* Only run response callable if response didn't start
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2022-02-01 15:08:24 +01:00
Oleksandr Fedorov
aff548ab18
Prevent BaseHTTPMiddleware from hiding errors of StreamingResponse ( #1459 )
...
* Prevent BaseHTTPMiddleware from hiding errors of StreamingResponse
* Apply notes from PR:
* remove `nonlocal app_exc`;
* add extra test.
* Fix formatting
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2022-01-31 11:12:15 +01:00
Alex Oleshkevich
a7c5a41396
Allow Session scoped cookies. ( #1387 )
...
* Allow Session scoped cookies.
* Update docs/middleware.md
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
* Improve typing.
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2022-01-12 10:57:47 +01:00
Amin Alaee
3c93a19cef
Add Mypy checks to tests ( #1353 )
2022-01-11 09:28:39 +01:00
Florimond Manca
6c9bc55af7
Prevent anyio.ExceptionGroup in error views under a BaseHTTPMiddleware ( #1262 )
...
* Prevent ExceptionGroup in error views under a BaseHTTPMiddleware
* Apply suggestion from @uSpike
Co-authored-by: euri10 <benoit.barthelet@gmail.com>
2021-10-28 18:50:33 +02:00
Hannes Küttner
7e675a0b86
Fix BadSignature exception handling in SessionMiddleware ( #1264 )
2021-08-14 15:38:50 +01:00