Connection Error
This hook function, if defined, is called every time an error occurred when processing the request or the method to notify the upper application and change the default behavior as shown shown in the figure Hook Functions. This function can analyses the error and change the status code and the file to return.
Prototype
void HTTPs_ErrHook (const HTTPs_INSTANCE *p_instance, HTTPs_CONN *p_conn, const void *p_hook_cfg, HTTPs_ERR err);
Arguments
p_instance
Pointer to the instance structure (read only).
p_conn
Pointer to the connection structure.
p_hook_cfg
Pointer to hook application data.
err
Internal error that occurred: see in http-s.h file HTTPs_ERR
enumeration for error codes.
Return Values
None.
Required Configuration
See section Hook Configuration.
Notes / Warnings
- The instance structure is for read-only. It must not be modified at any point in this hook function.
- The following connection attributes can be accessed to analyze the connection (see
HTTPs_CON
N in Control Structures for further details on each parameters):ClientAddr
Method
PathPtr
HdrCtr
HdrListPtr
- In this hook function, only the under-mentioned connection parameters are allowed to be modified (see
HTTPs_CONN
in Control Structures for further details on each parameters):StatusCode
PathPtr
DataPtr
DataLen
BodyDataType
ConnDataPtr
Example Template
The listing below demonstrates the µC/HTTP-server module capabilities. That code simply read error and print file not found errors.
Listing - Error Hook Example Code
static void HTTPs_ErrHook (const HTTPs_INSTANCE *p_instance, HTTPs_CONN *p_conn, const void *p_hook_cfg, HTTPs_ERR err) { switch (err) { case HTTPs_ERR_FILE_404_NOT_FOUND: printf("Error 404 File not found occurred.\n"); return; default: break; } }