This hook function, if defined, is called every time a new request has been received and processed as shown in the figure Hook Functions. This function can restrict the access to some resource by analyzing the connection parameter such as remote IP address, the method, resource requested, HTTP header fields, etc. It is also possible in this hook function to redirect to another file. If the upper application require memory or any specific resource to process the request it should be allocated into this hook function.
Prototype
Code Block |
---|
CPU_BOOLEAN HTTPs_ReqHook(const HTTPs_INSTANCE *p_instance,
HTTPs_CONN *p_conn,
const void *p_hook_cfg); |
Arguments
p_instance
Pointer to the instance structure (read only).
...
Listing bellow is shown to demonstrate the µC/HTTPs module capabilities. That code simply read all header field and print the cookie header field value.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
static CPU_BOOLEAN HTTPs_ReqHook(const HTTPs_INSTANCE *p_instance,
HTTPs_CONN *p_conn,
const void *p_hook_cfg)
{
#if (HTTPs_CFG_HDR_EN == DEF_ENABLED)
HTTPs_HDR_BLK *p_req_hdr_blk;
#endif
#if (HTTPs_CFG_HDR_EN == DEF_ENABLED)
p_req_hdr_blk = p_conn->ReqHdrFirstPtr;
while (p_req_hdr_blk != DEF_NULL) {
switch (p_req_hdr_blk->HdrField) {
case HTTP_HDR_FIELD_COOKIE:
printf("cookie received: %s\n", (CPU_CHAR *)p_req_hdr_blk->ValPtr);
break;
default:
break;
}
p_req_hdr_blk = p_req_hdr_blk->HdrBlkNextPtr;
}
#endif
return (DEF_OK);
} |