On Request Body Received Hook

This hook function, if defined, is called by μC/HTTP-server when data is received in the HTTP request body.  It allows the upper application  to parse the data received to save it or take action on it. The hook function wont be called when the HTTP server receives a POST request containing a form. In that case, the server core will take care of parsing the body and saving the data into CGI field blocks. See section Hook Functions for the diagram showing at what moment the hook is called in the HTTP transaction processing.

Prototype

CPU_BOOLEAN  HTTPs_ReqBodyRxHook (const  HTTPs_INSTANCE  *p_instance,
                                         HTTPs_CONN      *p_conn,
                                  const  void            *p_hook_cfg,
                                         void            *p_buf,
                                  const  CPU_SIZE_T       buf_size,
                                         CPU_SIZE_T      *p_buf_size_used);

Arguments

p_instance

Pointer to the instance structure (read only).

p_conn

Pointer to the connection structure (read only).

p_hook_cfg

Pointer to hook application data.

p_buf

Pointer to the data buffer.

buf_size

Size of the data received available inside the buffer.

p_buf_size_used

Pointer to the variable that will received the length of the data consumed by the app.

Return Value

DEF_YES

If the data have been consumed by the application.

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 since the response is mostly ready to be transmitted.

Example Template

The listing below is shown to demonstrate the µC/HTTP-server module capabilities. That code simply copies the data received in an application buffer.

Listing - Add Header Field Hook Function Example Code
#define  APP_BUF_LEN    4096

CPU_CHAR  AppBuf[APP_BUF_LEN];


static  CPU_BOOLEAN  HTTPs_ReqBodyRxHook (const  HTTPs_INSTANCE  *p_instance,
                                                 HTTPs_CONN      *p_conn,
                                          const  void            *p_hook_cfg,
												 void            *p_buf,
                                          const  CPU_SIZE_T       buf_size,
                                                 CPU_SIZE_T      *p_buf_size_used)
{
	static  CPU_INT16U  buf_ix = 0;
            CPU_INT16U  len;

 
	len = DEF_MIN(buf_size, (APP_BUF_LEN - buf_ix));
	if (len == 0) {
		return (DEF_NO);
	}

	Mem_Copy(&AppBuf[buf_ix], p_buf, len);

   *p_buf_size_used = len;
    buf_ix         += len;
 
	return (DEF_YES);
}