/
On Response Body
On Response Body
Called by the µC/HTTP-client core when body's data of the HTTP response is received.
The parameter HTTPc_PARAM_TYPE_RESP_BODY_HOOK
must be set up using the function HTTPc_ReqSetParam()
for the hook function to be called.
Prototype
CPU_INT32U HTTPc_RespBodyHook (HTTPc_CONN_OBJ *p_conn_obj, HTTPc_REQ_OBJ *p_req_obj, HTTP_CONTENT_TYPE content_type, void *p_data, CPU_INT32U data_len, CPU_BOOLEAN last_chunk);
Arguments
p_conn_obj
Pointer to the current HTTPc Connection Object.
p_req_obj
Pointer to the current HTTPc Request Object.
content_type
HTTP Content Type of the HTTP Response body's data.
p_data
Pointer to a data piece of the HTTP Response body.
p_data_len
Length of the data piece received.
last_chunk
DEF_YES
, if this is the last piece of data.
DEF_NO
, if more data is up coming.
Return Values
The number of bytes read during the callback.
Required Configuration
None.
Notes / Warnings
None.
Example Template
Listing - Response Body Callback Function Example Code
static void HTTPc_RespBodyHook (HTTPc_CONN_OBJ *p_conn, HTTPc_REQ_OBJ *p_req, HTTP_CONTENT_TYPE content_type, void *p_data, CPU_INT32U data_len, CPU_BOOLEAN last_chunk) { FS_FILE *p_file; FS_FLAGS fs_flags; CPU_SIZE_T size_wr; CPU_SIZE_T size_wr_tot; CPU_BOOLEAN is_open; FS_ERR err_fs; is_open = FSFile_IsOpen("\\index.html", &fs_flags, &err_fs); if (err_fs != FS_ERR_NONE) { return; } if (is_open == DEF_NO) { fs_flags = 0; DEF_BIT_SET(fs_flags, FS_FILE_ACCESS_MODE_WR); DEF_BIT_SET(fs_flags, FS_FILE_ACCESS_MODE_CREATE); DEF_BIT_SET(fs_flags, FS_FILE_ACCESS_MODE_TRUNCATE); p_file = FSFile_Open("index.html", fs_flags, &err_fs); if (err_fs != FS_ERR_NONE) { return; } } switch (content_type) { case HTTP_CONTENT_TYPE_HTML: if (p_data != DEF_NULL) { size_wr = 0; size_wr_tot = 0; while (size_wr < data_len) { size_wr = FSFile_Wr(p_file, p_data, data_len, &err_fs); if (err_fs != FS_ERR_NONE) { return; } size_wr_tot += size_wr; } } break; case HTTP_CONTENT_TYPE_OCTET_STREAM: case HTTP_CONTENT_TYPE_PDF: case HTTP_CONTENT_TYPE_ZIP: case HTTP_CONTENT_TYPE_GIF: case HTTP_CONTENT_TYPE_JPEG: case HTTP_CONTENT_TYPE_PNG: case HTTP_CONTENT_TYPE_JS: case HTTP_CONTENT_TYPE_PLAIN: case HTTP_CONTENT_TYPE_CSS: case HTTP_CONTENT_TYPE_JSON: default: break; } if (last_chunk == DEF_YES) { FSFile_Close(p_file, &err_fs); } }
Related content
On Request Body
On Request Body
More like this
Retrieve HTTP Response Data
Retrieve HTTP Response Data
More like this
On Response Chunk Hook
On Response Chunk Hook
More like this
HTTPs_RespBodySetParamStaticData
HTTPs_RespBodySetParamStaticData
More like this
On Request Body Received Hook
On Request Body Received Hook
More like this
On Request Header
On Request Header
More like this