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

Closed

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

Warnings
⚠️
	The **target branch** for this Pull Request **must be the default branch** of the project (`master`).

	If you would like to add this feature to a different branch, please state this in the PR description and we will consider it.

👋 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.
- Resolve all warnings (⚠️ ) before requesting a review from human reviewers - they will appreciate it.
- 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 6b1e5d0

@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

 62 files   62 suites   16m 34s ⏱️
 24 tests  18 ✅ 0 💤 6 ❌
140 runs  134 ✅ 0 💤 6 ❌

For more details on these failures, see this check.

Results for commit 6b1e5d0.

♻️ 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‼️ +23K0.00‼️ +2.610‼️ +3K0.00‼️ +6.93
ESP32S20‼️ +19K0.00‼️ +2.250‼️ +3K0.00‼️ +6.99
ESP32C30‼️ +23K0.00‼️ +2.420‼️ +2K0.00‼️ +6.67
ESP32C60‼️ +42K0.00‼️ +4.620‼️ +25K0.00‼️ +62.11
ESP320‼️ +23K0.00‼️ +2.430⚠️ +19600.00‼️ +3.99
Click to expand the detailed deltas report [usage change in BYTES]
TargetESP32S3ESP32S2ESP32C3ESP32C6ESP32
ExampleFLASHRAMFLASHRAMFLASHRAMFLASHRAMFLASHRAM
WebServer/examples/AdvancedWebServer‼️ +22K‼️ +3K‼️ +18K‼️ +2K‼️ +23K‼️ +2K‼️ +42K‼️ +25K‼️ +21K⚠️ +1800
WebServer/examples/FSBrowser‼️ +21K‼️ +3K‼️ +18K‼️ +3K‼️ +21K‼️ +2K‼️ +39K‼️ +24K‼️ +21K⚠️ +1816
WebServer/examples/Filters‼️ +22K‼️ +3K‼️ +18K‼️ +2K‼️ +23K‼️ +2K‼️ +42K‼️ +25K‼️ +21K⚠️ +1800
WebServer/examples/HelloServer‼️ +22K‼️ +3K‼️ +17K‼️ +2K‼️ +23K‼️ +2K‼️ +42K‼️ +25K‼️ +21K⚠️ +1800
WebServer/examples/HttpAdvancedAuth‼️ +22K‼️ +3K‼️ +18K‼️ +2K‼️ +22K‼️ +2K‼️ +42K‼️ +25K‼️ +21K⚠️ +1792
WebServer/examples/HttpAuthCallback‼️ +22K‼️ +3K‼️ +17K‼️ +2K‼️ +22K‼️ +2K‼️ +42K‼️ +25K‼️ +21K⚠️ +1792
WebServer/examples/HttpAuthCallbackInline‼️ +22K‼️ +3K‼️ +18K‼️ +2K‼️ +22K‼️ +2K‼️ +42K‼️ +25K‼️ +21K⚠️ +1792
WebServer/examples/HttpBasicAuth‼️ +22K‼️ +3K‼️ +18K‼️ +2K‼️ +22K‼️ +2K‼️ +42K‼️ +25K‼️ +21K⚠️ +1792
WebServer/examples/HttpBasicAuthSHA1‼️ +22K‼️ +3K‼️ +18K‼️ +2K‼️ +22K‼️ +2K‼️ +42K‼️ +25K‼️ +22K⚠️ +1792
WebServer/examples/HttpBasicAuthSHA1orBearerToken‼️ +22K‼️ +3K‼️ +18K‼️ +2K‼️ +22K‼️ +2K‼️ +41K‼️ +25K‼️ +22K⚠️ +1792
WebServer/examples/Middleware----------
WebServer/examples/MultiHomedServers‼️ +22K‼️ +3K‼️ +18K‼️ +2K‼️ +23K‼️ +2K‼️ +42K‼️ +25K‼️ +21K⚠️ +1792
WebServer/examples/PathArgServer‼️ +19K‼️ +3K‼️ +15K‼️ +3K‼️ +14K‼️ +2048‼️ +35K‼️ +24K‼️ +18K⚠️ +1960
WebServer/examples/SDWebServer‼️ +20K‼️ +3K‼️ +15K‼️ +2K‼️ +22K‼️ +2K‼️ +41K‼️ +24K‼️ +19K⚠️ +1776
WebServer/examples/SimpleAuthentification‼️ +23K‼️ +3K‼️ +19K‼️ +3K‼️ +22K⚠️ +2040‼️ +42K‼️ +24K‼️ +23K⚠️ +1808
WebServer/examples/UploadHugeFile‼️ +18K‼️ +3K‼️ +13K‼️ +2K‼️ +14K‼️ +2K‼️ +35K‼️ +25K‼️ +18K⚠️ +1960
WebServer/examples/WebServer‼️ +22K‼️ +3K‼️ +18K‼️ +3K‼️ +22K‼️ +2048‼️ +41K‼️ +24K‼️ +21K⚠️ +1784
WebServer/examples/WebUpdate‼️ +22K‼️ +3K‼️ +18K‼️ +2K‼️ +23K‼️ +2K‼️ +42K‼️ +25K‼️ +21K⚠️ +1792

@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 mathieucarbou force-pushed the middleware branch 3 times, most recently from 7f62ca4 to cf0f79a Compare September 25, 2024 13:08
@mathieucarbou mathieucarbou force-pushed the middleware branch 2 times, most recently from f8d4eea to 4668e78 Compare September 28, 2024 09:36
Copy link
Collaborator

@lucasssvaz lucasssvaz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Tested and it works as expected. Just a couple nitpicks.

@mathieucarbou
Copy link
Contributor Author

@lucasssvaz : thanks! I will update the PR soon.

@lucasssvaz
Copy link
Collaborator

lucasssvaz commented Oct 9, 2024

@mathieucarbou Also, as there are some changes to the WebServer. Maybe it would be better to target branch release/v3.1.x to make sure we don't introduce any unwanted breaking change by mistake. Probably you just need to rebase this PR and the commits on top of it.

@mathieucarbou
Copy link
Contributor Author

@mathieucarbou Also, as there are some changes to the WebServer. Maybe it would be better to target branch release/v3.1.x to make sure we don't introduce any unwanted breaking change by mistake. Probably you just need to rebase this PR and the commits on top of it.

Yes that would be better.

What do you think about the 3 bullet points above ? Could I also switch to std::list ?

@mathieucarbou mathieucarbou changed the base branch from master to release/v3.1.x October 9, 2024 12:35
@lucasssvaz
Copy link
Collaborator

lucasssvaz commented Oct 9, 2024

@mathieucarbou Also, as there are some changes to the WebServer. Maybe it would be better to target branch release/v3.1.x to make sure we don't introduce any unwanted breaking change by mistake. Probably you just need to rebase this PR and the commits on top of it.

Yes that would be better.

What do you think about the 3 bullet points above ? Could I also switch to std::list ?

I think it should be fine now that we are targeting v3.1.x as long as the flash usage increase is not very significant. There are too many changes from IDF recently that increased flash usage a lot and we are trying to optimize things for space.

What do you think @me-no-dev ?

@VojtechBartoska VojtechBartoska added this to the 3.1.1 milestone Oct 23, 2024
@me-no-dev me-no-dev deleted the branch espressif:release/v3.1.x December 18, 2024 13:56
@me-no-dev me-no-dev closed this Dec 18, 2024
@lucasssvaz
Copy link
Collaborator

@mathieucarbou Could you please reopen this targeting master ?

@mathieucarbou
Copy link
Contributor Author

@mathieucarbou Could you please reopen this targeting master ?

FYI, for next time, before deleting branches, just know that there is a github option to edit PRs and change the target branch. This allows keeping the history of PRs instead of having to recreate them. Here since the target branch was deleted, github closed the PR without a way to re-open it and change the target branch.

@me-no-dev
Copy link
Member

@mathieucarbou I did not expect the PR to be closed. The one for the libs was not closed and I switched the target branch after I deleted the 3.1.x one

@me-no-dev
Copy link
Member

Interesting what made this PR different. Maybe the fact that we were not given rights to edit it?

@mathieucarbou
Copy link
Contributor Author

Oh, that's right: "Allow edits and access to secrets by maintainers" was not checked, I just checked it now.

Why ? I do not know. This is always an option I usually keep on (I hate to block people or being blocked by this option).
I don't even know if there is a github option to keep it off by default.

Definitley, that must be this thing.

Do you know if this could be unchecked by default with the required CLA agreement ?

@me-no-dev
Copy link
Member

CLA bot comes after the PR is created, so I doubt that was it. GH has been a bit strange on a few fronts lately, so not unlikely that something else was the cause

@me-no-dev
Copy link
Member

trying to reopen

@me-no-dev
Copy link
Member

It's not allowing me to reopen it 😦

@mathieucarbou
Copy link
Contributor Author

It's not allowing me to reopen it 😦

yeah, same ;-) no worry, I have rebased already, I am doing another review (always good to re-read after a while). Will push in a few.

@Jason2866
Copy link
Collaborator

"Edit" is off when the PR is opened from an ORG repository.

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.

6 participants