Last changes in docs and minor refactor/fixes in typing in Server method
This commit is contained in:
parent
1bb84f9ee1
commit
17364edf80
3 changed files with 13 additions and 11 deletions
|
|
@ -32,7 +32,7 @@ HTTP Server for CircuitPython.
|
||||||
- Supports URL parameters and wildcard URLs.
|
- Supports URL parameters and wildcard URLs.
|
||||||
- Supports HTTP Basic and Bearer Authentication on both server and route per level.
|
- Supports HTTP Basic and Bearer Authentication on both server and route per level.
|
||||||
- Supports Websockets and Server-Sent Events.
|
- Supports Websockets and Server-Sent Events.
|
||||||
- Limited support for HTTPS (only on selected microcontrollers e.g. ESP32-S3).
|
- Limited support for HTTPS (only on selected microcontrollers with enough memory e.g. ESP32-S3).
|
||||||
|
|
||||||
|
|
||||||
Dependencies
|
Dependencies
|
||||||
|
|
|
||||||
|
|
@ -60,12 +60,14 @@ class Server: # pylint: disable=too-many-instance-attributes
|
||||||
"""Root directory to serve files from. ``None`` if serving files is disabled."""
|
"""Root directory to serve files from. ``None`` if serving files is disabled."""
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def _validate_https_cert_provided(certfile: str, keyfile: str) -> None:
|
def _validate_https_cert_provided(
|
||||||
if not certfile or not keyfile:
|
certfile: Union[str, None], keyfile: Union[str, None]
|
||||||
|
) -> None:
|
||||||
|
if certfile is None or keyfile is None:
|
||||||
raise ValueError("Both certfile and keyfile must be specified for HTTPS")
|
raise ValueError("Both certfile and keyfile must be specified for HTTPS")
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __create_circuitpython_ssl_context(certfile: str, keyfile: str) -> SSLContext:
|
def _create_circuitpython_ssl_context(certfile: str, keyfile: str) -> SSLContext:
|
||||||
ssl_context = create_default_context()
|
ssl_context = create_default_context()
|
||||||
|
|
||||||
ssl_context.load_verify_locations(cadata="")
|
ssl_context.load_verify_locations(cadata="")
|
||||||
|
|
@ -74,7 +76,7 @@ class Server: # pylint: disable=too-many-instance-attributes
|
||||||
return ssl_context
|
return ssl_context
|
||||||
|
|
||||||
@staticmethod
|
@staticmethod
|
||||||
def __create_cpython_ssl_context(certfile: str, keyfile: str) -> SSLContext:
|
def _create_cpython_ssl_context(certfile: str, keyfile: str) -> SSLContext:
|
||||||
ssl_context = create_default_context(purpose=Purpose.CLIENT_AUTH)
|
ssl_context = create_default_context(purpose=Purpose.CLIENT_AUTH)
|
||||||
|
|
||||||
ssl_context.load_cert_chain(certfile, keyfile)
|
ssl_context.load_cert_chain(certfile, keyfile)
|
||||||
|
|
@ -87,9 +89,9 @@ class Server: # pylint: disable=too-many-instance-attributes
|
||||||
@classmethod
|
@classmethod
|
||||||
def _create_ssl_context(cls, certfile: str, keyfile: str) -> SSLContext:
|
def _create_ssl_context(cls, certfile: str, keyfile: str) -> SSLContext:
|
||||||
return (
|
return (
|
||||||
cls.__create_circuitpython_ssl_context(certfile, keyfile)
|
cls._create_circuitpython_ssl_context(certfile, keyfile)
|
||||||
if implementation.name == "circuitpython"
|
if implementation.name == "circuitpython"
|
||||||
else cls.__create_cpython_ssl_context(certfile, keyfile)
|
else cls._create_cpython_ssl_context(certfile, keyfile)
|
||||||
)
|
)
|
||||||
|
|
||||||
def __init__(
|
def __init__(
|
||||||
|
|
|
||||||
|
|
@ -372,14 +372,14 @@ video to multiple clients while simultaneously handling other requests.
|
||||||
:emphasize-lines: 31-77,92
|
:emphasize-lines: 31-77,92
|
||||||
:linenos:
|
:linenos:
|
||||||
|
|
||||||
SSL/TLS (HTTPS)
|
HTTPS
|
||||||
---------------
|
-----
|
||||||
|
|
||||||
.. warning::
|
.. warning::
|
||||||
For now HTTPS on CircuitPython is **only supported on ESP32-S3 boards**.
|
HTTPS on CircuitPython **works only on boards with enough memory e.g. ESP32-S3**.
|
||||||
|
|
||||||
When you want to expose your server to the internet or an untrusted network, it is recommended to use HTTPS.
|
When you want to expose your server to the internet or an untrusted network, it is recommended to use HTTPS.
|
||||||
Together with authentication, it provides a secure way to communicate with the server, without the risk of eavesdropping.
|
Together with authentication, it provides a relatively secure way to communicate with the server.
|
||||||
|
|
||||||
.. note::
|
.. note::
|
||||||
Using HTTPS slows down the server, because of additional work with encryption and decryption.
|
Using HTTPS slows down the server, because of additional work with encryption and decryption.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue