On Response Chunk Hook

To allow the upper application to transmit data with the Chunked Transfer Encoding, this hook function is available. If defined, it will be called at the moment of the Response body transfer (as shown in section Hook Functions), and it will be called until the application has transfer all its data. If the hook is not required by the upper application, it can be set as DEF_NULL and no function will be called.

Furthermore, for the hook to be called, the RespBodyDataType parameter of HTTPs_CONN must be set to HTTPs_BODY_DATA_TYPE_STATIC_DATA and the DataPtr parameter must be null. Please refer to section Response Body Data for more details on how to send application data in chunk.

Prototype

CPU_BOOLEAN  HTTPs_RespChunkDataGetHook(const  HTTPs_INSTANCE  *p_instance,
                                               HTTPs_CONN      *p_conn,
									    const  void            *p_hook_cfg,
									           void            *p_buf,
                                               CPU_SIZE_T       buf_len_max,
                                               CPU_SIZE_T      *p_tx_len);


Arguments

p_instance

Pointer to the instance structure (read only).

p_conn

Pointer to the connection structure.

p_hook_cfg

Pointer to hook application data.

p_buf

Pointer to the buffer to fill.

buf_len_max

Maximum length the buffer can contain.

p_tx_len

 Pointer to variable that will received the length written in the buffer.


Return Values

DEF_YES

if there is no more data to send.

DEF_NO

Otherwise.

Required Configuration

See section Hook Configuration.

Notes / Warnings

  • The instance structure is for read-only. It must not be modified.
  • Connection structure must not be modified by this function. All the parameters to change are already passed as arguments.

Example Template

The listing below demonstrates the µC/HTTP-server module capabilities. 

Listing - CGI Poll Hook Function Example Code
static  CPU_BOOLEAN  HTTPs_RespChunkDataGetHook (const  HTTPs_INSTANCE  *p_instance,
                                                        HTTPs_CONN      *p_conn,
												 const  void            *p_hook_cfg,
												        void            *p_buf,
                                                        CPU_SIZE_T       buf_len_max,
                                                        CPU_SIZE_T      *p_tx_len)
{
#if (HTTPs_CFG_FORM_EN == DEF_ENABLED)
    const  HTTPs_CFG      *p_cfg = p_instance->CfgPtr;
           HTTPs_KEY_VAL  *p_key_val;
           CPU_INT16S      str_cmp;


    str_cmp = Str_Cmp_N(p_conn->PathPtr, FORM_SUBMIT_URL, p_conn->PathLenMax);
    if (str_cmp == 0) {
                                                                /* Construct JSON for user                              */
        Str_Copy(p_buf, "{\"user\": {\"first name\": \"");      /* Add First Name field.                                */
        p_key_val = p_conn->FormDataListPtr;
        while (p_key_val != DEF_NULL) {
            str_cmp = Str_Cmp_N(p_key_val->KeyPtr, "firstname", p_cfg->FormCfgPtr->KeyLenMax);
            if (str_cmp == 0) {
                Str_Cat_N(p_buf, p_key_val->ValPtr, p_key_val->ValLen);
                break;
            }
            p_key_val = p_key_val->NextPtr;
        }
        Str_Cat(p_buf, "\", \"last name\":\"");                 /* Add Last Name field.                                 */
        p_key_val = p_conn->FormDataListPtr;
        while (p_key_val != DEF_NULL) {
            str_cmp = Str_Cmp_N(p_key_val->KeyPtr, "lastname", p_cfg->FormCfgPtr->KeyLenMax);
            if (str_cmp == 0) {
                Str_Cat_N(p_buf, p_key_val->ValPtr, p_key_val->ValLen);
                break;
            }
            p_key_val = p_key_val->NextPtr;
        }
        Str_Cat(p_buf, "\"}}");
    }
   *p_tx_len = Str_Len_N(p_buf, p_cfg->BufLen);
#else
    CPU_SW_EXCEPTION(;);
#endif
    return (DEF_YES);
}