Add Response Header Field
This hook function is called by µC/HTTPs before starting to transmit the response message as shown on Figure 4-1. 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
void RespHdrTxFnctPtr (const HTTPs_INSTANCE *p_instance, HTTPs_CONN *p_conn); |
Arguments
p_instance
Pointer to the instance structure (read only).
p_conn
Pointer to the connection structure (read only).
Return ValueS
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 29
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 is shown to demonstrate the µC/HTTPs module capabilities. That code simply add two header fields to a response message for an HTML document.
static CPU_BOOLEAN HTTPs_InstanceRespHdrTx (const HTTPs_INSTANCE *p_instance, HTTPs_CONN *p_conn) { #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 == (HTTPs_HDR_BLK *)0) { 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 == (HTTPs_HDR_BLK *)0) { 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); } |
-
- Add Header field hook function example code
- Ensure that we don’t add header field to a response with an error
- Make sure to add header field only on HTML document.
- Acquire and add a first header field block of type ‘Cookie’ and with a string value type to the connection
- Set the value string value (cookie content) and the string length.
- Acquire and add a second header field block of type ‘Server’ and with a string value type to the connection
- Set the value string value (server name) and the string length.
- Add Header field hook function example code