On Request Header
Called by the µC/HTTPc core to allow the application to include a Header Field to the ongoing HTTP Request.
The parameter HTTPc_PARAM_TYPE_REQ_HDR_HOOK
must be set up using the function HTTPc_ReqSetParam()
for the hook function to be called.
Prototype
CPU_BOOLEAN HTTPc_ReqHdrHook (HTTPc_CONN_OBJ *p_conn_obj, HTTPc_REQ_OBJ *p_req_obj, HTTP_HDR **p_hdr);
Arguments
p_conn_obj
Pointer to the current HTTPc Connection Object.
p_req_obj
Pointer to the current HTTPc Request Object.
p_hdr
Variable that will received the pointer to the header field to include in the HTTP request.
Return Values
DEF_YES
, if all the header fields have been passed by the application.
DEF_NO
, if header fields remain to be passed by the application (Hook function will be called again).
Required Configuration
- The
HTTPc_CFG_HDR_TX_EN
configuration macro MUST be enabled.
Notes / Warnings
- The header field object MUST stay valid until the HTTP transaction is completed.
Example Template
Listing - Request Header Callback Function Example Code
#define HTTPc_HDR_VAL_LEN_MAX 10 HTTPc_HDR HTTPc_ReqHdr; CPU_CHAR HTTPc_ReqHdrValStr[HTTPc_HDR_VAL_LEN_MAX]; static CPU_BOOLEAN HTTPc_ReqHdrHook (HTTPc_CONN_OBJ *p_conn, HTTPc_REQ_OBJ *p_req, HTTPc_HDR **p_hdr) { HTTPc_HDR *p_hdr_tmp; p_hdr_tmp = &HTTPc_ReqHdr; p_hdr_tmp->ValPtr = &HTTPc_ReqHdrValStr[0]; p_hdr_tmp->HdrField = HTTP_HDR_FIELD_COOKIE; Str_Copy_N(p_hdr_tmp->ValPtr, "ID=234668", HTTPc_HDR_VAL_LEN_MAX); p_hdr_tmp->ValLen = Str_Len_N(p_hdr_tmp->ValPtr, HTTPc_HDR_VAL_LEN_MAX); *p_hdr = p_hdr_tmp; return (DEF_YES); }