-
Notifications
You must be signed in to change notification settings - Fork 32
4.0.0 - Huge refactor, more examples, authentication, configurable MIMETypes #54
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
4.0.0 - Huge refactor, more examples, authentication, configurable MIMETypes #54
Conversation
… method IDE was getting confused by decorated method and was not displaying the type hint properly
Just out of curiosity I tried starting multiple servers on one board at the same time, of couse on diffrent ports.
|
289f75e
to
415218b
Compare
415218b
to
61135f1
Compare
I tested this out today on a Feather S2 TFT. It seems to work great, I do have a few changes to suggest:
|
2ad4a4c
to
a424d27
Compare
abdcb05
to
3359668
Compare
During a recent Deep Dive stream from @FoamyGuy, @Neradoc suggested implementing default handlers for specific error types. Current implementation does not allow that, I am now working on rewrite of This is a moderately large change and it requires a lot of changes in docs, examples and nearly a complete rewrite of response logic. I will try to include it inside this PR as including it in future 5.0.0 and again reinventing the API might be frustrating, as all code that uses |
I believe current state of this PR is satisfying. All the changes, both added initially and ones added after creating PR are listed in the first post above, with EDIT next to them if they were added/modified later. I do not plan any more features here, already there are plenty of new ones. This PR is a good foundation for implementing e.g. middleware or default handlers in the future, if the need for them comes. Testing and code reviews or any other feedback would be appreciated. |
…or-authentication-mimetypes
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is looking good to me at this point.
I tested nearly all examples in this repo on a Feather S2 TFT 8.1.0-rc.0.
I submitted adafruit/Adafruit_Learning_System_Guides#2511 to update the only usage outside of this repo that I could find. I searched the Learn repo and the Library Bundle Examples.
Thank you again for all of the improvements to this library @michalpokusa!
Thank you for testing and merging! 👍 |
Updating https://github.com/adafruit/Adafruit_CircuitPython_EPD to 2.11.2 from 2.11.1: > Merge pull request adafruit/Adafruit_CircuitPython_EPD#65 from sdomoszlai13/fix-annotations-epd.py Updating https://github.com/adafruit/Adafruit_CircuitPython_asyncio to 0.5.21 from 0.5.20: > Merge pull request adafruit/Adafruit_CircuitPython_asyncio#41 from Neradoc/fix-package-prefix Updating https://github.com/adafruit/Adafruit_CircuitPython_HTTPServer to 4.0.0 from 3.0.2: > Merge pull request adafruit/Adafruit_CircuitPython_HTTPServer#54 from michalpokusa/4.0.0-examples-refactor-authentication-mimetypes > Run pre-commit > Update pre-commit hooks > Merge pull request adafruit/Adafruit_CircuitPython_HTTPServer#53 from adafruit/not-robust Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Updated download stats for the libraries
New Features 🎉:
- Added
Basic
andBearer
authentication options on server and per route level- Rewritten logic for
MIMETypes
, now it is possible to remove unused, thus saving memory, and register new ones-
root_path
inServer
constructor is now optional, if not specified orNone
, access to filesystem is disabled, which resolves #52-
request
parameter in handler functions now has access toserver
that received it- EDIT1:
Request.json()
for easy parsing of JSON POST data- EDIT1:
host
andport
attributes onServer
- EDIT1: Debug mode for displaying messages useful during development
- EDIT1: Added
append_slash
toServer.route
- EDIT2: Added
...
and....
wildcards- EDIT3: New classes fro reponse types:
ChunkedResponse
,JSONResponse
,FileResponse
,Redirect
- Added ability to stop and start a
Server
again- Documented option to host multiple servers on single board, despite not being the intended use, it is possible and might be useful in some cases
Modified Features 🏗️:
-
server.route()
now can accept list of methods in addition to single one- Routes now respect trailing
/
at the end of a path, so/example
and/example/
are two diffrent paths-
serve_forever
does not raise any error and continues to work no matter what-
Response.send_file default to root_path instead of root of the filesystem- EDIT3:
Response
is now separated into many classes for diffrent usages like sending file or JSON data- EDIT3:
Response
objects are now returned from handler functions instead of being used in context managers, this makes them easier and more intuitive to use, repalced all public methods with classes that have same functionality- URL parameters are now keyword instead of positional, which makes them much more flexible
Refactor ⚙️:
- Removed
HTTP...
from class names in order to unify naming with other libs, so e.g.HTTPServer
becomesServer
,HTTPRequest
becomesRequest
etc.- It is now possible to import directly from
adafruit_httpserver
instead of using multiple import statements for each component- Replaced
CommonHTTPStatus
with objects ofStatus
class- EDIT1: Refactor of
_Routes
and_Route
classesDocs 📘:
- Updated docs to new API
- Added new examples that show previously unexplained usages
- Added
:emphasize-lines:
to examples to mark most important parts of themTesting of these changes would be greatly appreciated 😉