Commit Graph

31 Commits

Author SHA1 Message Date
Marcelo Trylesinski bd77d7d9f0
Enforce `__future__.annotations` (#2483) 2024-02-29 10:16:42 +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
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
Marcelo Trylesinski b5126b2063
Raise `WebSocketDisconnect` when `WebSocket.send()` excepts `IOError` (#2425)
* Raise `WebSocketDisconnect` when `WebSocket.send()` excepts `IOError`

* Restrict the IOError
2024-01-20 08:08:22 -07:00
Marcelo Trylesinski 8d7630bda1
Add type hint on `test_websockets.py` (#2411)
* Add type hint on `test_websockets.py`

* Add type ignore on mock_receive
2024-01-12 03:06:48 -07: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
夏悠然 a1ee8b4f45
Set `ensure_ascii=False` on `json.dumps()` for `WebSocket.send_json()` (#2341)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2023-12-01 13:23:06 +00:00
Marcelo Trylesinski 657e7e7b72
Send reason on `WebSocketDisconnect` (#2309) 2023-10-22 12:44:09 -06: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 d425c84b10
Skip test when brotli is installed (#1620)
* Skip test when brotli is installed

* A better reason message
2022-05-05 11:04:10 +02:00
Adrian Garcia Badaracco 18398e7ee2
Convert ASGI 2.0 apps in tests to ASGI 3 (#1476) 2022-02-07 08:58:30 -06:00
Amin Alaee 424351cb23
Replace WebSocket assertions with RuntimeError (#1472)
Co-authored-by: Tom Christie <tom@tomchristie.com>
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2022-02-04 11:51:04 +01:00
Amin Alaee 34d9f0f10f
Add reason to WebSocket closure (#1417)
Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2022-01-22 17:11:32 +01:00
Roman Vlasenko 9d282a937c
Default WebSocket accept message headers to an empty list (#1422)
* If no extra headers are passed, set it to an empty list

* Test websocket.accept() with no additional headers

* Update starlette/websockets.py

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

* Update tests/test_websockets.py

Co-authored-by: Amin Alaee <mohammadamin.alaee@gmail.com>

* Update tests/test_websockets.py

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

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
Co-authored-by: Amin Alaee <mohammadamin.alaee@gmail.com>
2022-01-22 15:09:18 +01:00
matiuszka 9d686a7125
Additional headers for WS `accept` message. (#1361)
* Additional headers for WS accept message.

* Update tests/test_websockets.py

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

* fixup! Additional headers for WS accept message.

* Update tests/test_websockets.py

Co-authored-by: Marcelo Trylesinski <marcelotryle@gmail.com>
2022-01-06 11:55:29 +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
Thomas Grainger 906e9073a4
reset the `__eq__` and `__hash__` of HTTPConnection to allow WebSockets to be added to … (#1039) 2021-06-28 13:02:18 +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
Tom Christie 78f7095d7e
Websocket iter (#838)
* Add iter_text, iter_bytes, iter_json to WebSocket

* Add run_until_first_complete for weksocket sender/receiver branching
2020-02-20 15:43:03 +00:00
Tom Christie 38b9ee339a
Add iter_text, iter_bytes, iter_json to WebSocket (#837) 2020-02-20 13:03:19 +00:00
Tom Christie 1ee194739f
WebSockets now default to sending JSON using text dataframes (#349) 2019-01-25 15:27:39 +00:00
Tom Christie bcf876c686
Use isort for consistent import ordering (#156) 2018-10-29 14:46:42 +00:00
Tom Christie 67b8d71601
Revisit WebSocket status codes (#119) 2018-10-18 08:47:04 +01:00
Jeff Buttars eed466abbc Add http and websocket status codes with descriptive variables (#43)
* Add status.py for http and websocket status code with descriptive
variable names.

* Fix import of status

* Add status usage to tests

* change wsconnect to websocket_connect

* Update with master
2018-10-17 12:31:20 +01:00
Tom Christie 94044e5991
Tweaks to URL datastructure (#81)
* Tweaks to URL datastructure

* Linting
2018-10-05 11:29:06 +01:00
Tom Christie a24ba66556 Type hinting 2018-10-02 13:24:02 +01:00
Marcos Schroh 041381e40c Missing annotations on websockets module. (#69)
* fix(Missing annotation): missing annotations added on websockets module.

* fix(websockets annotations): implied optionals should be used.
2018-10-02 13:15:33 +01:00
Tom Christie 78d1829758
Version 0.3 (#57)
* Renamings

* Version 0.3.0

* Black formatting

* Update docs for 0.3
2018-09-05 11:39:38 +01:00
Jordan Eremieff f4fe0ec312 Name changes (#55)
* Rename View -> HTTPEndpoint

* Rename views doc file -> endpoints

* Rename request/response files -> requests/responses, update imports, update docs

* Rename WebSocketSession -> WebSocket, rename session -> websocket in docs

* Full module imports in tests and source, removing imports from __init__ file

* Fix name in testclient doc
2018-09-05 10:29:04 +01:00
Tom Christie 2519f83765 client.wsconnect -> client.websocket_connect 2018-08-28 14:45:06 +01:00
Tom Christie 6f948e95b4
WebSockets support (#37)
* WebSockets support

* WebSockets support

* WebSockets support

* Black formatting

* Add missing descriptions against websocket test session docs

* Add missing descriptions against websocket test session docs

* Add note on session.send() / session.receive()
2018-08-17 16:36:48 +01:00