Victor Westerhuis
ca1f45dc12
Use ETag from headers when parsing If-Range in FileResponse ( #2761 )
2024-12-03 08:07:22 +01:00
Marcelo Trylesinski
7d586f7e39
Support for `send` client disconnect to HTTP ( #2732 )
2024-11-18 21:56:13 +01: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
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
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
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
Adrian Garcia Badaracco
d1b38037e7
Allow use of `memoryview` with `Response` ( #2577 )
2024-06-01 13:12:34 +00:00
Bas Schoenmaeckers
9fd3eccef1
Allow returning memoryview in StreamingResponse ( #2576 )
2024-04-22 12:15:24 -05: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
Mikkel Duif
b8eebef387
Avoid duplicate charset on `Content-Type` ( #2443 )
...
* fix(response): avoid duplicated charset
* Update docs/responses.md
---------
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2024-02-03 08:39:01 +00:00
Giovanni Barillari
7936e86f0a
Add support for ASGI `pathsend` extension ( #2435 )
...
* add support for ASGI `pathsend` extension
* add test for ASGI `pathsend`
2024-01-22 02:44:40 -07:00
Sebastián Ramírez
3734e85c18
♻️ Do not use the deprecated `method` parameter in `FileResponse` inside of `StaticFiles` ( #2406 )
...
* ♻️ Do not use the deprecated `method` parameter in `FileResponse` inside of` StaticFile`
* ✅ Add test for warning FileResponse with method argument
* 🔊 Remove warning filter for FileResponse with method
2024-01-11 08:17:18 -07:00
Marcelo Trylesinski
6715eb4f4f
Deprecate `FileResponse(method=...)` parameter ( #2366 )
2023-12-16 12:47:54 +00:00
dependabot[bot]
1ed1737e32
Bump mypy from 1.5.1 to 1.7.1 ( #2357 )
...
Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2023-12-13 12:56:11 +00:00
Viicos
7c8ca17773
Use mypy `strict` ( #2180 )
...
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2023-07-23 15:41:50 -06:00
kraptor
5771a78c14
Fix test not passing in 32-bit architectures ( #2033 )
...
Some architectures cannot hold values after
2038 year.
This commit fixes the following tests, adjusting
the expiring date for the cookies to a maximum
year value of 2037:
* test_set_cookie
* test_expires_on_set_cookie
2023-02-11 15:24:57 +01:00
oskipa
0a63a6e586
Support `str` and `datetime` on `expires` parameter on the `set_cookie` method ( #1908 )
...
Co-authored-by: Hugo Estrada <hugoestrada@cal.berkeley.edu>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Florimond Manca <florimond.manca@protonmail.com>
2023-02-06 05:45:30 +00:00
Marcelo Trylesinski
6765502c1e
Replace HTTP client on TestClient from `requests` to `httpx` ( #1376 )
2022-09-06 07:43:32 +02:00
Jean Hominal
25a52fe52a
Test StreamingResponse behavior on receiving http.disconnect ( #1727 )
2022-07-02 20:11:46 +02:00
qu1ck
6ad5a6a97f
Add content disposition type parameter to FileResponse ( #1266 )
...
disposition "attachment" causes browsers to download
the file. E.g. "inline" will will be attempted to be
displayed directly.
Co-authored-by: Tom Christie <tom@tomchristie.com>
2022-02-14 16:08:28 +00:00
Amin Alaee
5a5a5c367f
Make `content` argument required to `JSONResponse` ( #1431 )
...
Co-authored-by: Tom Christie <tom@tomchristie.com>
2022-01-26 17:11:33 +01:00
Marcelo Trylesinski
2d6ddd3861
Don't set headers for responses with 1xx, 204 and 304 status code ( #1397 )
...
* Don't set headers for responses with 1xx, 204 and 304 status code
* Fix test
Co-authored-by: Tom Christie <tom@tomchristie.com>
2022-01-10 12:08:31 +01:00
Marcelo Trylesinski
4633427816
Don't omit `Content-Length` header for `Content-Length: 0` cases ( #1395 )
...
* Add content-length header by default
* Add test for #1099
* Revert changes and add tests
* Check if is StreamingResponse or FileResponse before adding content-length headers
* Change conditional logic to check if body is present
2022-01-07 12:48:21 +01:00
Thomas Grainger
d222b87cb4
TestClient accepts backend and backend_options as arguments to constructor ( #1211 )
...
as opposed to ClassVar assignment
Co-authored-by: Jamie Hewland <jhewland@gmail.com>
Co-authored-by: Jordan Speicher <jordan@jspeicher.com>
Co-authored-by: Jordan Speicher <uSpike@users.noreply.github.com>
2021-06-28 21:36:13 +01:00
Jordan Speicher
42592d68e5
anyio integration ( #1157 )
...
* First whack at anyio integration
* Fix formatting
* Remove debug messages
* mypy fixes
* Update README.md
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
* Fix install_requires typo
* move_on_after blocks if deadline is too small
* Linter fixes
* Improve WSGI structured concurrency
* Tests use anyio
* Checkin progress on testclient
* Prep for anyio 3
* Remove debug backend option
* Use anyio 3.0.0rc1
* Remove old style executor from GraphQLApp
* Fix extra import
* Don't cancel task scope early
* Wait for wsgi sender to finish before exiting
* Use memory object streams in websocket tests
* Test on asyncio, asyncio+uvloop, and trio
* Formatting fixes
* run_until_first_complete doesn't need a return
* Fix middleware app call
* Simplify middleware exceptions
* Use anyio for websocket test
* Set STARLETTE_TESTCLIENT_ASYNC_BACKEND in tests
* Pass async backend to portal
* Formatting fixes
* Bump anyio
* Cleanup portals and add TestClient.async_backend
* Use anyio.run_async_from_thread to send from worker thread
* Use websocket_connect as context manager
* Document changes in TestClient
* Formatting fix
* Fix websocket raises coverage
* Update to anyio 3.0.0rc3 and replace aiofiles
* Apply suggestions from code review
Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
* Bump to require anyio 3.0.0 final
* Remove mention of aiofiles in README.md
* Pin jinja2 to releases before 3 due to DeprecationWarnings
* Add task_group as application attribute
* Remove run_until_first_complete
* Undo jinja pin
* Refactor anyio.sleep into an event
* Use one less task in test_websocket_concurrency_pattern
* Apply review suggestions
* Rename argument
* fix start_task_soon type
* fix BaseHTTPMiddleware when used without Starlette
* Testclient receive() is a non-trapping function if the response is already complete
This allows for a zero deadline when waiting for a disconnect message
* Use variable annotation for async_backend
* Update docs regarding dependency on anyio
* Use CancelScope instead of move_on_after in request.is_disconnected
* Cancel task group after returning middleware response
Add test for https://github.com/encode/starlette/issues/1022
* Add link to anyio backend options in testclient docs
* Add types-dataclasses
* Re-implement starlette.concurrency.run_until_first_complete and add a test
* Fix type on handler callable
* Apply review comments to clarify run_until_first_complete scope
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Alex Grönholm <alex.gronholm@nextday.fi>
Co-authored-by: Thomas Grainger <tagrain@gmail.com>
2021-06-18 15:48:43 +01:00
Ben Falk
f997938916
use quote instead of quote_plus for RedirectResponse location header ( #1164 )
...
* use quote instead of quote_plus for RedirectResponse location header
adjust safe characters: rem. duplicate & symbol
add test for redirect quoting
* remove unused import
Co-authored-by: Jamie Hewland <jhewland@gmail.com>
2021-04-14 20:14:53 +01:00
Jamie Hewland
99b37781eb
Remove UJSONResponse ( #1047 )
...
* Remove UJSONResponse
* Add documentation about custom JSON serialization
2020-11-08 22:49:12 +02:00
witling
a9f8821f3b
fix 793: allow custom async iterator ( #1041 )
...
* fix 793
* custom async generator: implement pr notes
* custom async generator: cleanup dependencies
* update tests
* newline at end of tests
* fix linting
* Update tests/test_responses.py
Co-authored-by: Jamie Hewland <jhewland@gmail.com>
* Update tests/test_responses.py
Co-authored-by: Jamie Hewland <jhewland@gmail.com>
* fix naming for custom generator tests
* comply with pep 492
* Shift streaming tests to be in one place
Co-authored-by: witling <noreply@my.email>
Co-authored-by: Jamie Hewland <jhewland@gmail.com>
2020-10-21 20:10:30 +02:00
Daniel Hedrén
00c365a4fb
SameSite support for cookies ( #732 )
...
* Add samesite support to cookies
* Cleanup
Remove unnecessary import and str()
* SameSite "lax" default, enforce valid options
* Update signature
2020-02-25 12:27:15 +00:00
Eugene Molotov
1e406655fe
Allow non latin-1 filename in FileResponse ( #792 )
2020-02-17 14:14:30 +00:00
Tom Christie
ca65c9b5ca
Fix pytest.raises usage
2019-07-04 15:53:21 +01:00
Tom Christie
99057dd538
request.scope and request.state
2019-06-19 10:08:19 +01:00
Mantas
1654a48fa4
Allow None fore JSONResponse
...
Previously `JSONResponse(None)` rendered empty string, but it should be
'null' instead.
This change fixes it.
2019-06-17 17:20:08 +03:00
Tom Christie
7414099e65
Make StreamingResponse compatible with normal iterators ( #462 )
...
* Add concurrency.iterator_to_async, tests and docs
* Make StreamingResponse compatible with normal iterators
* Format and typo in docs
* Rename helper function to iterate_in_threadpool
* Version 0.12.0.b3
2019-04-03 10:29:00 +01:00
Tom Christie
4d5708e468
ASGI 3 ( #435 )
...
* TestClient supports ASGI2 and ASGI3
* Starlette instances present ASGI3 interface
* ServerErrorMiddleware presents ASGI3 interface
* Use ASGI3 protocol throughout
* Response signatures match ASGI interface.
2019-03-19 16:03:19 +00:00
Tom Christie
b3ad311bbc
Template component ( #398 )
...
* Add Jinja2Templates component
* Fix imports
* Prevent code formatters from moving deliberatly late import
2019-02-18 13:28:18 +00:00
Taoufik
0c3a1e4a60
f-strings everywhere ( #334 )
...
* f-strings everywhere
2019-01-22 16:24:46 +00:00
Tom Christie
93a124805f
Drop body from responses on HEAD requests ( #317 )
...
* Drop body from responses on HEAD requests
* Linting
* Endpoints supporting HEAD should automatically support GET
2019-01-14 11:07:23 +00:00
Florimond Manca
81d3697ba5
fix population of content-type and content-length headers ( #291 )
2018-12-26 17:13:51 +00:00
Tom Christie
4745fb1aef
Add TemplateResponse. ( #269 )
...
* Add TemplateResponse. Expose .template and .context info to test client.
* Only send 'http.response.template' if the extension is include
* Add TemplateResponse to documentation
2018-12-13 15:16:25 +00:00
Tom Christie
c504323eaf
Default to empty body on responses ( #208 )
2018-11-09 17:59:58 +00:00
zya-performance
552e0f6f2d
adds background task param to StreamingResponse and FileResponse ( #167 )
...
* adds background task param to StreamingResponse
* allows FileResponse to run a background task after last bye is sent
* test StreamingResponse and FileResponse with background task
* linted
* added a blank line to match CI expectations
2018-11-05 11:38:05 +00:00
Tom Christie
bcf876c686
Use isort for consistent import ordering ( #156 )
2018-10-29 14:46:42 +00:00
Alexander Botello
cdb08bc644
Drop support for `StaticFile` ( #145 )
...
* Add runtime checks inside FileResponse w/ tests
* Drop support of StaticFile
* update documentation
2018-10-28 18:04:17 +00:00