Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.
Comment: Published by Scroll Versions from this space and version 3.00.00

To configure and edit the response body data, the µC/HTTP-server stack offers three API functions:

HTTPs_RespBodySetParamFileThis function can be used to transmit in the response body a file contained in a File System (a standard FS or the HTTP Static FS) . See section Specify File to Send in Response Body.
HTTPs_RespBodySetParamStaticDataThis function can be used to transmit data contained in an application buffer or also to specify that the data should be sent with the Chunked Transfer Encoding. See sections Send data contained in Application Buffer and Send data with the Chunk Hook.
HTTPs_RespBodySetParamNoBodyThis function can be used to specify that no body should be added in the HTTP response.

Those three API functions should be used by the upper application inside one of two hook functions: Connection Request and CGI Post.

Specify File to Send in Response Body
Anchor
File
File

Code Block
languagemicrium
CPU_BOOLEAN  App_OnReqHook (const  HTTPs_INSTANCE  *p_instance,                                
                                   HTTPs_CONN      *p_conn,
                            const  void            *p_hook_cfg)
{
    HTTPs_ERR  err_https;


	HTTPs_RespBodySetParamFile(p_instance, 
                               p_conn,
                               "index.html", 
                               HTTP_CONTENT_TYPE_HTML,
                               DEF_NO,
                              &err_https);

	return (DEF_YES);
}

 

Send data contained in Application Buffer 
Anchor
Static Data
Static Data

Code Block
languagemicrium
#define   APP_BUF_LEN   20
CPU_CHAR  AppBuf[APP_BUF_LEN];

CPU_BOOLEAN  App_OnReqHook (const  HTTPs_INSTANCE  *p_instance,                                
                                   HTTPs_CONN      *p_conn,
                            const  void            *p_hook_cfg)
{
	HTTPs_ERR  err_https;


	Str_Copy_N(&AppBuf[0], "Hello World", APP_BUF_LEN);
    data_len = Str_Len_N(&AppBuf[0], APP_BUF_LEN);

    HTTPs_RespBodySetParamStaticData (p_instance,                                               
                                      p_conn,
                                      HTTP_CONTENT_TYPE_PLAIN,
                                     &AppBuf[0],
                                      data_len,
                                      DEF_NO,
                                     &err_https);

	return (DEF_YES);
}

 

Send data with the Chunk Hook
Anchor
Chunk
Chunk

Code Block
languagemicrium
CPU_BOOLEAN  App_OnReqHook (const  HTTPs_INSTANCE  *p_instance,                                
                                   HTTPs_CONN      *p_conn,
                            const  void            *p_hook_cfg)
{
	HTTPs_ERR  err_https;


    HTTPs_RespBodySetParamStaticData (p_instance,                                               
                                      p_conn,
                                      HTTP_CONTENT_TYPE_JSON,
                                      DEF_NULL,
                                      0,
                                      DEF_NO,
                                     &err_https);

	return (DEF_YES);
}

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)
{
}