This hook function, if defined, is called by μC/HTTPs HTTP-server before starting to transmit the response message as shown on Figure 4-1 Hook Functions. It allows the upper application to add header field to the response by calling a specific API function with header field type and value.
Prototype
Code Block |
---|
CPU_BOOLEAN HTTPs_RespHdrTxHook (const HTTPs_INSTANCE *p_instance,
HTTPs_CONN *p_conn,
const void *p_hook_cfg); |
Arguments
p_instance
Pointer to the instance structure (read only).
p_conn
Pointer to the connection structure (read only).
...
p_hook_cfg
Pointer to hook application data.
Return Value
DEF_YES
If all header fields are added without error.
DEF_NO
otherwise.
Required Configuration
See section 4-4-6 “Instance Header Field Configuration” on page 29HTTPs_CFG_HDR_EN
must be enabled in the http-s_cfg.h file (see section Module Configuration).
The header feature must also be enabled in the Instance configuration (see section Instance Parameters Configuration).
See section Hook Configuration.
Notes / Warnings
- The instance structure is for read-only. It must not be modified.
- Connection structure must not be modified by this function since the response is mostly ready to be transmitted.
Example Template
Listing 4-18 The listing below is shown to demonstrate the µC/HTTPs HTTP-server module capabilities. That code simply add It adds two header fields to a response message for an HTML document.L4-21(1)
Code Block | ||||
---|---|---|---|---|
| ||||
static CPU_BOOLEAN HTTPs_RespHdrTxHook (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_resp_hdr_blk;
const HTTPs_CFG *p_cfg;
CPU_CHAR *str_data;
CPU_SIZE_T str_len;
HTTPs_ERR http_err;
p_cfg = p_instance->CfgPtr;
switch (p_conn->StatusCode) {
case HTTPs_STATUS_OK: (1)
if (p_conn->FileContentType == HTTPs_CONTENT_TYPE_HTML) { (2)
p_resp_hdr_blk = HTTPs_RespHdrGet(p_instance, (3)
p_conn,
HTTPs_HDR_FIELD_SET_COOKIE,
HTTPs_HDR_VAL_TYPE_STR_DYN,
&http_err);
if (p_resp_hdr_blk == DEF_NULL) {
return(DEF_FAIL);
}
str_data = "user=micrium";
str_len = Str_Len_N(str_data, p_cfg->RespHdrStrLenMax);
Str_Copy_N(p_resp_hdr_blk->ValPtr, (4)
str_data,
str_len);
p_resp_hdr_blk->ValLen = str_len;
p_resp_hdr_blk = HTTPs_RespHdrGet(p_instance, (5)
p_conn,
HTTPs_HDR_FIELD_SERVER,
HTTPs_HDR_VAL_TYPE_STR_DYN,
&http_err);
if (p_resp_hdr_blk == DEF_NULL) {
return(DEF_FAIL);
}
str_data = "uC-HTTPs V2.00.00";
str_len = Str_Len_N(str_data, p_cfg->RespHdrStrLenMax); (6)
Str_Copy_N(p_resp_hdr_blk->ValPtr,
str_data,
str_len);
p_resp_hdr_blk->ValLen = str_len;
}
break;
default:
break;
}
#endif
return (DEF_YES);
} |
...
Panel | ||
---|---|---|
| ||
|
...
|
...
|
...
|
...
|
...
|