On Request Body
Called by the µC/HTTP-client core to retrieve from the application the body data to put in the ongoing HTTP Request.
The parameter HTTPc_PARAM_TYPE_REQ_BODY_HOOK
must be set up using the function HTTPc_ReqSetParam()
for the hook function to be called. This hook function is used for both the Standard Transfer (content length of body is specified) and for the Chunked Transfer Encoding.
This hook function gives the choice to set the pointer to the application data (with p_data argument) that the µC/HTTP-client stack will take care of transferring; or to directly copy the data in the HTTP transmit buffer (with p_buf argument).
Prototype
CPU_BOOLEAN HTTPc_ReqBodyHook (HTTPc_CONN_OBJ *p_conn_obj, HTTPc_REQ_OBJ *p_req_obj, void **p_data, CPU_CHAR *p_buf, CPU_INT16U *p_buf_len CPU_INT16U *p_data_len);
Arguments
p_conn_obj
Pointer to the current HTTPc Connection Object.
p_req_obj
Pointer to the current HTTPc Request Object.
p_data
Variable that will received the pointer to the data chunk to include in the HTTP request.
p_buf
Pointer to the HTTP transmit buffer.
buf_len
Length remaining in the HTTP transmit buffer.
p_data_len
Length of the data chunk.
Return Values
DEF_YES
, if all the data to transmit have been passed by the application.
DEF_NO
, if data to transmit remains to be passed by the application (Hook function will be called again).
Required Configuration
None.
Notes / Warnings
- The data to transmit MUST stay valid until the HTTP transaction is completed.
Example Template
CPU_CHAR AppHTTPc_ReqBodyBuf[1024]; static CPU_BOOLEAN HTTPc_ReqBodyHook (HTTPc_CONN_OBJ *p_conn, HTTPc_REQ_OBJ *p_req, void **p_data, CPU_CHAR *p_buf, CPU_INT16U buf_len, CPU_INT16U *p_data_len) { CPU_SIZE_T data_len; data_len = App_ReadDataStream(&AppHTTPc_ReqBodyBuf); /* Theoretical application's function to read a stream of data and ... */ /* ... copy it in the buffer and return the length of data copied. */ *p_data = &AppHTTPc_ReqBodyBuf; *p_data_len = data_len; if (data_len == 0) { return (DEF_YES); } else { return (DEF_NO); } }