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.
The error handler is unsafe. Is there a good reason for that?
There was a problem hiding this comment.
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_lenanduser_ctxfields 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.
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.
Should most likely not be pub
| Ok(()) | ||
| } | ||
|
|
||
| fn register_error_handler(&mut self, handler: ErrorHandler) -> Result<()> { |
There was a problem hiding this comment.
Is de-registration of these necessary, on server stop?
There was a problem hiding this comment.
probably, I'll check
8a8adba to
5ccb542
Compare
Necessary for the captive portal