...
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
Code Block |
---|
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.
...
Notes / Warnings
None.
Example Template
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
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);
}
} |