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: http server error handler #11

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

Conversation

ForsakenHarmony
Copy link
Contributor

@ForsakenHarmony ForsakenHarmony commented Oct 26, 2021

Necessary for the captive portal

pub struct ErrorHandler {
error: HttpdError,
// handler: Box<dyn Fn(Request, HttpdError) -> Result<Response>>,
handler: unsafe extern "C" fn(req: *mut httpd_req_t, error: httpd_err_code_t) -> esp_err_t,
Copy link
Collaborator

Choose a reason for hiding this comment

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

The error handler is unsafe. Is there a good reason for that?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Semi good reason, the error handler doesn't get the user_ctx like the normal handler does, so this has to be a unique function that gets called

When invoked, the validity of uri, method, content_len and user_ctx fields of the httpd_req_t parameter is not guaranteed as the HTTP request may be partially received/parsed.

It should be possible to work around it with a global Mutex or something else

}

pub struct ErrorHandler {
error: HttpdError,
Copy link
Collaborator

Choose a reason for hiding this comment

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

How am I supposed to use this pub struct outside of esp-idf-svc given that its members are private?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should most likely not be pub

@@ -273,6 +367,17 @@ impl Server {
Ok(())
}

fn register_error_handler(&mut self, handler: ErrorHandler) -> Result<()> {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is de-registration of these necessary, on server stop?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

probably, I'll check

@ivmarkov ivmarkov force-pushed the master branch 3 times, most recently from 8a8adba to 5ccb542 Compare July 5, 2023 19:27
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants