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

Clean up CORS implemention #662

Merged
merged 1 commit into from
Jan 17, 2025
Merged

Clean up CORS implemention #662

merged 1 commit into from
Jan 17, 2025

Conversation

eandersson
Copy link
Collaborator

  • Use the internal AP state for CORS.
  • Made ip_in_private_range a bit more readable.
  • Re-factored code a bit.


static esp_err_t is_network_allowed(httpd_req_t * req)
{
if (GLOBAL_STATE->SYSTEM_MODULE.ap_enabled == true) {
Copy link
Collaborator

Choose a reason for hiding this comment

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

We should probably not use our own variable to keep the state as it can be error prone if someone forgets to call it, instead we should call the esp_wifi_get_mode fn, which is the source of truth.

Copy link
Owner

Choose a reason for hiding this comment

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

is there a good reason to keep a shadow copy of the AP state?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yep - I agree, but as a compromise for performance re-using the existing variable should be significantly more performant. Since it is directly controlled by the WiF component the risk that it isn't updated should be pretty low.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Copy link
Contributor

Choose a reason for hiding this comment

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

To chime in late, did you time the function call? As I think it's very unlikely it would cause a significant overhead compared to do a full HTTP request. Sounds like premature optimisation to me. And as you all know, Premature Optimisation Is the Root of All Evil.

Copy link
Collaborator Author

@eandersson eandersson Jan 20, 2025

Choose a reason for hiding this comment

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

We can add a utility function in the future to add this back, but it was also fixing a bug in the code. For me it was mostly around using the same source of truth for all our code.

@skot
Copy link
Owner

skot commented Jan 17, 2025

confirmed iOS setup AP works, and CSRF doesn't 👍

@skot skot merged commit 06be7f5 into master Jan 17, 2025
2 checks passed
@eandersson eandersson deleted the cleanup_cors branch January 18, 2025 13:00
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants