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

feat(webserver): Middleware with default middleware for cors, authc, curl-like logging #10186

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

mathieucarbou
Copy link
Contributor

@mathieucarbou mathieucarbou commented Aug 17, 2024

This PR improves WebServer with the following additions:

  • Add Middleware support (aka Expressif) with some built-in middlewares like cors, authc and logging
  • Add ability to collect all incoming request headers
  • Added response code and info on server

As discussed in #10185, I tested the example thanks to a pio config.

Ideally it would be nice if @me-no-dev and @ayushsharma82 could review this PR, both were involved in these parts.

Copy link
Contributor

github-actions bot commented Aug 17, 2024

Messages
📖 🎉 Good Job! All checks are passing!

👋 Hello mathieucarbou, we appreciate your contribution to this project!


Click to see more instructions ...


This automated output is generated by the PR linter DangerJS, which checks if your Pull Request meets the project's requirements and helps you fix potential issues.

DangerJS is triggered with each push event to a Pull Request and modify the contents of this comment.

Please consider the following:
- Danger mainly focuses on the PR structure and formatting and can't understand the meaning behind your code or changes.
- Danger is not a substitute for human code reviews; it's still important to request a code review from your colleagues.
- To manually retry these Danger checks, please navigate to the Actions tab and re-run last Danger workflow.

Review and merge process you can expect ...


We do welcome contributions in the form of bug reports, feature requests and pull requests.

1. An internal issue has been created for the PR, we assign it to the relevant engineer.
2. They review the PR and either approve it or ask you for changes or clarifications.
3. Once the GitHub PR is approved we do the final review, collect approvals from core owners and make sure all the automated tests are passing.
- At this point we may do some adjustments to the proposed change, or extend it by adding tests or documentation.
4. If the change is approved and passes the tests it is merged into the default branch.

Generated by 🚫 dangerJS against 4668e78

@mathieucarbou mathieucarbou changed the title Arduino WebServer improvements feat: Middleware support for WebServer Aug 17, 2024
Copy link
Contributor

github-actions bot commented Aug 17, 2024

Test Results

 56 files   -  83   56 suites   - 83   4m 15s ⏱️ - 1h 38m 23s
 21 tests  -   9   21 ✅  -   9  0 💤 ±0  0 ❌ ±0 
135 runs   - 168  135 ✅  - 168  0 💤 ±0  0 ❌ ±0 

Results for commit 4668e78. ± Comparison against base commit b05f18d.

This pull request removes 9 tests.
performance.coremark.test_coremark ‑ test_coremark
performance.fibonacci.test_fibonacci ‑ test_fibonacci
performance.psramspeed.test_psramspeed ‑ test_psramspeed
performance.ramspeed.test_ramspeed ‑ test_ramspeed
performance.superpi.test_superpi ‑ test_superpi
test_touch_errors
test_touch_interrtupt
test_touch_read
validation.periman.test_periman ‑ test_periman

♻️ This comment has been updated with latest results.

Copy link
Contributor

github-actions bot commented Aug 17, 2024

Memory usage test (comparing PR against master branch)

The table below shows the summary of memory usage change (decrease - increase) in bytes and percentage for each target.

MemoryFLASH [bytes]FLASH [%]RAM [bytes]RAM [%]
TargetDECINCDECINCDECINCDECINC
ESP32S30‼️ +3K0.00⚠️ +0.33000.000.00
ESP32S20‼️ +3K0.00⚠️ +0.34000.000.00
ESP32C30‼️ +2K0.00⚠️ +0.210⚠️ +160.00⚠️ +0.04
ESP32C60‼️ +2K0.00⚠️ +0.220⚠️ +160.00⚠️ +0.04
ESP320‼️ +3K0.00⚠️ +0.32000.000.00
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32S3ESP32S2ESP32C3ESP32C6ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
WebServer/examples/AdvancedWebServer‼️ +3K0‼️ +3K0⚠️ +2044⚠️ +16‼️ +2K0‼️ +3K0
WebServer/examples/FSBrowser‼️ +3K0‼️ +3K0⚠️ +20400‼️ +2048⚠️ +16‼️ +3K0
WebServer/examples/Filters‼️ +3K0‼️ +3K0‼️ +2K⚠️ +16⚠️ +20460‼️ +3K0
WebServer/examples/HelloServer‼️ +3K0‼️ +3K0‼️ +2K⚠️ +16⚠️ +20460‼️ +3K0
WebServer/examples/HttpAdvancedAuth‼️ +3K0‼️ +3K0⚠️ +20280⚠️ +20360‼️ +3K0
WebServer/examples/HttpAuthCallback‼️ +3K0‼️ +3K0⚠️ +20380⚠️ +20280‼️ +3K0
WebServer/examples/HttpAuthCallbackInline‼️ +3K0‼️ +3K0⚠️ +20360⚠️ +20280‼️ +3K0
WebServer/examples/HttpBasicAuth‼️ +3K0‼️ +3K0⚠️ +20360⚠️ +20300‼️ +3K0
WebServer/examples/HttpBasicAuthSHA1‼️ +3K0‼️ +3K0⚠️ +20360⚠️ +20280‼️ +3K0
WebServer/examples/HttpBasicAuthSHA1orBearerToken‼️ +3K0‼️ +3K0⚠️ +2038⚠️ +16⚠️ +2028⚠️ +16‼️ +3K0
WebServer/examples/Middleware----------
WebServer/examples/MultiHomedServers‼️ +3K0‼️ +3K0⚠️ +20320⚠️ +20320‼️ +3K0
WebServer/examples/PathArgServer‼️ +3K0‼️ +3K0⚠️ +20400⚠️ +20400‼️ +3K0
WebServer/examples/SDWebServer‼️ +3K0‼️ +3K0‼️ +2K0⚠️ +2044⚠️ +16‼️ +3K0
WebServer/examples/SimpleAuthentification‼️ +3K0‼️ +3K0⚠️ +20100⚠️ +2018⚠️ +16‼️ +3K0
WebServer/examples/UploadHugeFile‼️ +3K0‼️ +3K0⚠️ +2044⚠️ +16‼️ +2K0‼️ +3K0
WebServer/examples/WebServer‼️ +3K0‼️ +3K0‼️ +2K0‼️ +2K0‼️ +3K0
WebServer/examples/WebUpdate‼️ +3K0‼️ +3K0⚠️ +20400⚠️ +20320‼️ +3K0

@Jason2866
Copy link
Collaborator

@mathieucarbou Do you see the possibility to make this enhancement optional?
The size increase is not just a few bytes.

@mathieucarbou
Copy link
Contributor Author

mathieucarbou commented Aug 17, 2024

@mathieucarbou Do you see the possibility to make this enhancement optional? The size increase is not just a few bytes.

I saw that and I was surprised by it... I don't feel to have written 2k of code...

@mathieucarbou mathieucarbou reopened this Aug 17, 2024
@mathieucarbou mathieucarbou force-pushed the middleware branch 2 times, most recently from bc2dc4b to 6607a91 Compare August 17, 2024 15:04
@VojtechBartoska VojtechBartoska added the Status: Review needed Issue or PR is awaiting review label Aug 21, 2024
@VojtechBartoska VojtechBartoska added the Area: Libraries Issue is related to Library support. label Aug 21, 2024
@mathieucarbou
Copy link
Contributor Author

Adding a ref to: #10221 (comment)

@mathieucarbou mathieucarbou changed the title feat: Middleware support for WebServer feat(webserver) Middleware support for WebServer with default middlewares for cors, authc, curl-like logging Sep 6, 2024
@mathieucarbou mathieucarbou changed the title feat(webserver) Middleware support for WebServer with default middlewares for cors, authc, curl-like logging feat(webserver) Middleware with default middleware for cors, authc, curl-like logging Sep 6, 2024
@VojtechBartoska VojtechBartoska changed the title feat(webserver) Middleware with default middleware for cors, authc, curl-like logging feat(webserver): Middleware with default middleware for cors, authc, curl-like logging Sep 16, 2024
@mathieucarbou
Copy link
Contributor Author

@safocl : I would be glad to revisit this PR but only if there is a real motivation coming from the Espressif team to merge it.

Otherwise I won't spend my time updating a PR for nothing.

I have already implemented middleware support in the fork of https://github.com/mathieucarbou/ESPAsyncWebServer we maintain (https://github.com/mathieucarbou/ESPAsyncWebServer) and also in v2 branch of PsychicHttp (https://github.com/hoeken/PsychicHttp) which is the future version, with a lot of supported middlewares for CORS, Authc, authz, curl like logging, etc.

@me-no-dev
Copy link
Member

I would be glad to revisit this PR but only if there is a real motivation coming from the Espressif team to merge it.

There is interest. we are trying to finish up some big tasks and have a good look at this PR

@mathieucarbou mathieucarbou force-pushed the middleware branch 2 times, most recently from 521bbaa to 93c630f Compare September 25, 2024 12:38
@mathieucarbou
Copy link
Contributor Author

mathieucarbou commented Sep 25, 2024

@safocl : thank your for your review

@me-no-dev : thank you for your confirmation

I have reworked the PR to clean it - as it was it was more a PoC waiting for some interest. So I correctly did it and cleaned up the things saw by @safocl and much more.

I saw several things that I really don't like in WebServer:

  1. Returning String instead of const String&: I saw a bunch of placed where a String copy would be done in the return instead of returning a ref. Sadly, fixing that would break backward compatibility

  2. Use of chained pointers: this just makes the code error prone and harder to read with all these boilerplate loops. I would rather use std::list instead, but since I didn't see any usage of that (and only a few about vector), I don't know if there's a reason why the Arduino core code would not use it ? Especially that in the case of WebServer, the number of elements in such list would not be high enough to trigger any downsides of using them.

  3. Last point is more about organisation: the file structure inside src folder is quite fuzzy I find... Also WebServer.h would need a bit of re-ordering / api doc : there are so many public methods, and a mix of them for request and response.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area: Libraries Issue is related to Library support. Status: Review needed Issue or PR is awaiting review
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants