Skip to content

Commit 83ea10d

Browse files
authored
Merge pull request #63 from michalpokusa/external-routes-websockets-sse
External Routes, Server-Sent Events, Websockets
2 parents e0b2ba9 + 5e57a64 commit 83ea10d

30 files changed

+800
-115
lines changed

Diff for: README.rst

+1
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ HTTP Server for CircuitPython.
3131
- Supports chunked transfer encoding.
3232
- Supports URL parameters and wildcard URLs.
3333
- Supports HTTP Basic and Bearer Authentication on both server and route per level.
34+
- Supports Websockets and Server-Sent Events.
3435

3536

3637
Dependencies

Diff for: adafruit_httpserver/__init__.py

+5-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries, Michał Pokusa
22
#
33
# SPDX-License-Identifier: MIT
44
"""
@@ -58,7 +58,10 @@
5858
ChunkedResponse,
5959
JSONResponse,
6060
Redirect,
61+
SSEResponse,
62+
Websocket,
6163
)
64+
from .route import Route, as_route
6265
from .server import (
6366
Server,
6467
NO_REQUEST,
@@ -68,6 +71,7 @@
6871
)
6972
from .status import (
7073
Status,
74+
SWITCHING_PROTOCOLS_101,
7175
OK_200,
7276
CREATED_201,
7377
ACCEPTED_202,

Diff for: adafruit_httpserver/authentication.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
1+
# SPDX-FileCopyrightText: Copyright (c) 2023 Michał Pokusa
22
#
33
# SPDX-License-Identifier: MIT
44
"""

Diff for: adafruit_httpserver/exceptions.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
1+
# SPDX-FileCopyrightText: Copyright (c) 2023 Michał Pokusa
22
#
33
# SPDX-License-Identifier: MIT
44
"""

Diff for: adafruit_httpserver/headers.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Michał Pokusa
22
#
33
# SPDX-License-Identifier: MIT
44
"""

Diff for: adafruit_httpserver/methods.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Michał Pokusa
22
#
33
# SPDX-License-Identifier: MIT
44
"""

Diff for: adafruit_httpserver/mime_types.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries, Michał Pokusa
22
#
33
# SPDX-License-Identifier: MIT
44
"""

Diff for: adafruit_httpserver/request.py

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries, Michał Pokusa
22
#
33
# SPDX-License-Identifier: MIT
44
"""
@@ -302,8 +302,8 @@ def form_data(self) -> Union[FormData, None]:
302302
return self._form_data
303303

304304
def json(self) -> Union[dict, None]:
305-
"""Body of the request, as a JSON-decoded dictionary."""
306-
return json.loads(self.body) if self.body else None
305+
"""Body of the request, as a JSON-decoded dictionary. Only available for POST requests."""
306+
return json.loads(self.body) if (self.body and self.method == "POST") else None
307307

308308
@property
309309
def _raw_header_bytes(self) -> bytes:

0 commit comments

Comments
 (0)