Skip to content

Commit 93e2a96

Browse files
authored
fix(internal): use websocket in favor of websocket_route (#30)
* fix(internal): use `websocket` in favor of `websocket_route` * docs: add changes to `CHANGELOG.md`
1 parent 0acc1d2 commit 93e2a96

File tree

4 files changed

+12
-8
lines changed

4 files changed

+12
-8
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2222

2323
## [Unreleased]
2424

25+
### Changed
26+
27+
- [#30](https://github.com/WSH032/fastapi-proxy-lib/pull/30) - fix(internal): use `websocket` in favor of `websocket_route`. Thanks [@WSH032](https://github.com/WSH032)!
28+
2529
## [0.1.0] - 2023-12-01
2630

2731
### Security

src/fastapi_proxy_lib/core/websocket.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -700,7 +700,7 @@ async def close_proxy_event(_: FastAPI) -> AsyncIterator[None]:
700700
701701
app = FastAPI(lifespan=close_proxy_event)
702702
703-
@app.websocket_route("/{path:path}")
703+
@app.websocket("/{path:path}")
704704
async def _(websocket: WebSocket, path: str = ""):
705705
return await proxy.proxy(websocket=websocket, path=path)
706706

tests/app/echo_ws_app.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ def get_app() -> AppDataclass4Test: # noqa: C901, PLR0915
1919
request_dict = RequestDict(request=None)
2020
test_app_dataclass = AppDataclass4Test(app=app, request_dict=request_dict)
2121

22-
@app.websocket_route("/echo_text")
22+
@app.websocket("/echo_text")
2323
async def echo_text(websocket: WebSocket):
2424
"""Websocket endpoint for echo text. Just receive text and send it back.
2525
@@ -36,7 +36,7 @@ async def echo_text(websocket: WebSocket):
3636
except WebSocketDisconnect:
3737
break
3838

39-
@app.websocket_route("/echo_bytes")
39+
@app.websocket("/echo_bytes")
4040
async def echo_bytes(websocket: WebSocket):
4141
"""Websocket endpoint for echo bytes. Just receive bytes and send it back.
4242
@@ -53,7 +53,7 @@ async def echo_bytes(websocket: WebSocket):
5353
except WebSocketDisconnect:
5454
break
5555

56-
@app.websocket_route("/accept_foo_subprotocol")
56+
@app.websocket("/accept_foo_subprotocol")
5757
async def accept_foo_subprotocol(websocket: WebSocket):
5858
"""When client send subprotocols request, if subprotocols contain "foo", will accept it."""
5959
nonlocal test_app_dataclass
@@ -69,7 +69,7 @@ async def accept_foo_subprotocol(websocket: WebSocket):
6969

7070
await websocket.close()
7171

72-
@app.websocket_route("/just_close_with_1001")
72+
@app.websocket("/just_close_with_1001")
7373
async def just_close_with_1001(websocket: WebSocket):
7474
"""Just do nothing after `accept`, then close ws with 1001 code."""
7575
nonlocal test_app_dataclass
@@ -79,15 +79,15 @@ async def just_close_with_1001(websocket: WebSocket):
7979
await asyncio.sleep(0.3)
8080
await websocket.close(1001)
8181

82-
@app.websocket_route("/reject_handshake")
82+
@app.websocket("/reject_handshake")
8383
async def reject_handshake(websocket: WebSocket):
8484
"""Will reject ws request by just calling `websocket.close()`."""
8585
nonlocal test_app_dataclass
8686
test_app_dataclass.request_dict["request"] = websocket
8787

8888
await websocket.close()
8989

90-
@app.websocket_route("/do_nothing")
90+
@app.websocket("/do_nothing")
9191
async def do_nothing(websocket: WebSocket):
9292
"""Will do nothing except `websocket.accept()`."""
9393
nonlocal test_app_dataclass

tests/test_docs_examples.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ async def close_proxy_event(_: FastAPI) -> AsyncIterator[None]:
8989

9090
app = FastAPI(lifespan=close_proxy_event)
9191

92-
@app.websocket_route("/{path:path}")
92+
@app.websocket("/{path:path}")
9393
async def _(websocket: WebSocket, path: str = ""):
9494
return await proxy.proxy(websocket=websocket, path=path)
9595

0 commit comments

Comments
 (0)