-
Notifications
You must be signed in to change notification settings - Fork 182
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
base: master
Are you sure you want to change the base?
feat: http server error handler #11
Conversation
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, |
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.
The error handler is unsafe. Is there a good reason for that?
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.
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
anduser_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, |
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.
How am I supposed to use this pub
struct outside of esp-idf-svc
given that its members are private?
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.
Should most likely not be pub
@@ -273,6 +367,17 @@ impl Server { | |||
Ok(()) | |||
} | |||
|
|||
fn register_error_handler(&mut self, handler: ErrorHandler) -> Result<()> { |
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.
Is de-registration of these necessary, on server stop?
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.
probably, I'll check
8a8adba
to
5ccb542
Compare
Necessary for the captive portal