Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

External Routes, Server-Sent Events, Websockets #63

Merged
merged 21 commits into from
Jul 31, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
8ee162d
Changed Route class to public
michalpokusa Jul 12, 2023
e6a0b02
Minor refactor of passing URL parameters to handler
michalpokusa Jul 13, 2023
802d7fd
Added Server.add_routes for importing external routes
michalpokusa Jul 13, 2023
8fa70b6
Preparing for returning persistent connection responses
michalpokusa Jul 13, 2023
90085c3
Minor tweaks in _send_headers
michalpokusa Jul 13, 2023
28ae6e5
Added SSEResponse class
michalpokusa Jul 13, 2023
ebb7ca7
Added example for SSEResponse
michalpokusa Jul 13, 2023
1e1ad58
Added Websocket class and SWITCHING_PROTOCOLS_101
michalpokusa Jul 13, 2023
4047ef5
Added example for Websocket
michalpokusa Jul 13, 2023
86d11c9
Modified neopixel example to use Server.add_routes()
michalpokusa Jul 13, 2023
20a4eda
Updated docs
michalpokusa Jul 13, 2023
d372f8e
CI fixes, reformating etc.
michalpokusa Jul 13, 2023
e34d27d
Fix: Wrong returns in docstring
michalpokusa Jul 13, 2023
5c30a2a
Added as_route decorator as shorthand for creating Route objects
michalpokusa Jul 16, 2023
9dfaf80
Merge remote-tracking branch 'origin/main' into external-routes-webso…
michalpokusa Jul 18, 2023
d4dc768
Included ethernet example in docs, fixes to emphasized lines
michalpokusa Jul 18, 2023
978a0c9
Minor change in as_route docstring
michalpokusa Jul 21, 2023
d389013
Modified as_route docstring to be more verbose
michalpokusa Jul 21, 2023
4063b5a
Updated Copyright headers
michalpokusa Jul 30, 2023
7d8c0b1
Made SSE and Websocket examples more visual
michalpokusa Jul 31, 2023
5e57a64
Fix: Wrong method in example and .json() for non-POST requests
michalpokusa Jul 31, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ HTTP Server for CircuitPython.
- Supports chunked transfer encoding.
- Supports URL parameters and wildcard URLs.
- Supports HTTP Basic and Bearer Authentication on both server and route per level.
- Supports Websockets and Server-Sent Events.


Dependencies
Expand Down
6 changes: 5 additions & 1 deletion adafruit_httpserver/__init__.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries, Michał Pokusa
#
# SPDX-License-Identifier: MIT
"""
Expand Down Expand Up @@ -58,7 +58,10 @@
ChunkedResponse,
JSONResponse,
Redirect,
SSEResponse,
Websocket,
)
from .route import Route, as_route
from .server import (
Server,
NO_REQUEST,
Expand All @@ -68,6 +71,7 @@
)
from .status import (
Status,
SWITCHING_PROTOCOLS_101,
OK_200,
CREATED_201,
ACCEPTED_202,
Expand Down
2 changes: 1 addition & 1 deletion adafruit_httpserver/authentication.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2023 Michał Pokusa
#
# SPDX-License-Identifier: MIT
"""
Expand Down
2 changes: 1 addition & 1 deletion adafruit_httpserver/exceptions.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2023 Michał Pokusa
#
# SPDX-License-Identifier: MIT
"""
Expand Down
2 changes: 1 addition & 1 deletion adafruit_httpserver/headers.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2022 Michał Pokusa
#
# SPDX-License-Identifier: MIT
"""
Expand Down
2 changes: 1 addition & 1 deletion adafruit_httpserver/methods.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2022 Michał Pokusa
#
# SPDX-License-Identifier: MIT
"""
Expand Down
2 changes: 1 addition & 1 deletion adafruit_httpserver/mime_types.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries, Michał Pokusa
#
# SPDX-License-Identifier: MIT
"""
Expand Down
6 changes: 3 additions & 3 deletions adafruit_httpserver/request.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries
# SPDX-FileCopyrightText: Copyright (c) 2022 Dan Halbert for Adafruit Industries, Michał Pokusa
#
# SPDX-License-Identifier: MIT
"""
Expand Down Expand Up @@ -302,8 +302,8 @@ def form_data(self) -> Union[FormData, None]:
return self._form_data

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

@property
def _raw_header_bytes(self) -> bytes:
Expand Down
Loading