Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Anchor10973541097354 Add Response Header Field Anchor11040761104076This hook function, if defined, is called by µCμC/HTTPs HTTP-server before starting to transmit the response message as shown on Figure 4-1 Hook Functions. It allows the upper application to add header field to the response by calling a specific API function with header field type and value. Anchor11040931104093

Prototype

...

rowspan5

...

Code Block
CPU_BOOLEAN  HTTPs_RespHdrTxHook (const  HTTPs_INSTANCE  *p_instance,
                                         HTTPs_CONN      *p_conn,
                                  const  void            *p_hook_cfg);

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.

Return Value

DEF_YES

...

If all header fields are added without error.

...

...

DEF_NO

...

otherwise.

...

Required Configuration

Anchor11041041104104 See section 4-4-6 “Instance Header Field Configuration” on page 29 Anchor11041051104105HTTPs_CFG_HDR_EN must be enabled in the http-s_cfg.h file (see section Module Configuration).

The header feature must also be enabled in the Instance configuration (see section Instance Parameters 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

Anchor10979291097929 Listing 4-18 The listing below is shown to demonstrate the µC/HTTPs HTTP-server module capabilities. That code simply add It adds two header fields to a response message for an HTML document.anchor

Code Block

...

language

...

static CPU_BOOLEAN HTTPs_InstanceRespHdrTx (const HTTPs_INSTANCE *p_instance, HTTPs_CONN *p_conn) { #if

           HTTPs_HDR_BLK  *p_resp_hdr_blk;
const

	const  HTTPs_CFG      *p_cfg;

           CPU_CHAR       *str_data;

           CPU_SIZE_T      str_len;

           HTTPs_ERR       http_err;
 

    
      
	p_cfg = p_instance->CfgPtr;
switch


    switch (p_conn->StatusCode)
{ case
 {
	    case HTTPs_STATUS_OK:
(1) if
                                                              (1)
             if (p_conn->FileContentType == HTTPs_CONTENT_TYPE_HTML) {
(2)
                     (2)
                 p_resp_hdr_blk = HTTPs_RespHdrGet(p_instance,
(3) p_conn,
                             (3)
                                                   p_conn,
                                                   HTTPs_HDR_FIELD_SET_COOKIE,

                                                   HTTPs_HDR_VAL_TYPE_STR_DYN,

                                                  &http_err);
if

                 if (p_resp_hdr_blk ==
(HTTPs_HDR_BLK *)0) {
 DEF_NULL) {
                     return(DEF_FAIL);
} str_data =

                 }

				 str_data = "user=micrium";

                 str_len = Str_Len_N(str_data, p_cfg->RespHdrStrLenMax);

                 Str_Copy_N(p_resp_hdr_blk->ValPtr,
(4) str_data, str_len);
                                        (4)
                            str_data,
                            str_len);

                 p_resp_hdr_blk->ValLen = str_len;
 
                    
          
                 p_resp_hdr_blk = HTTPs_RespHdrGet(p_instance,
(5) p_conn,
                             (5)
                                                   p_conn,
                                                   HTTPs_HDR_FIELD_SERVER,

                                                   HTTPs_HDR_VAL_TYPE_STR_DYN,

                                                  &http_err);
if

                 if (p_resp_hdr_blk ==
(HTTPs_HDR_BLK *)0) {
 DEF_NULL) {
                     return(DEF_FAIL);
}   str_data =

                 }
          
                 str_data = "uC-HTTPs V2.00.00";

                 str_len = Str_Len_N(str_data, p_cfg->RespHdrStrLenMax);
(6)
                   (6)
                 Str_Copy_N(p_resp_hdr_blk->ValPtr,
str_data, str_len);

                            str_data,
                            str_len);

                 p_resp_hdr_blk->ValLen = str_len;
} break;   default: break; } #endif return

             }
             break;
          
         default:
             break;
	}
#endif

	return (DEF_YES);

}
summary
classCode_Listing
Table Row (tr)
Table Cell (td)
Anchor
10980311098031
Anchor
10980321098032
Anchor
10980331098033
Anchor
11048291104829
cpp
HTML Table
titleListing - Add Header Field Hook Function Example Code
static  CPU_BOOLEAN  HTTPs_RespHdrTxHook (const  HTTPs_INSTANCE  *p_instance,
                                                 HTTPs_CONN      *p_conn,
                                          const  void            *p_hook_cfg)
{
#if (HTTPs_CFG_HDR_EN == DEF_ENABLED)
Anchor
10980361098036
Anchor
10980371098037
Anchor
10980381098038
Anchor
10980391098039
Anchor
10980401098040
Anchor
10980411098041
Anchor
10980431098043
Table Row (tr)
Table Cell (td)
Anchor
11047701104770
Anchor
11047711104771
Anchor
11047731104773
Anchor
11047741104774
Anchor
11047751104775
Anchor
11047761104776
Anchor
11047771104777
Anchor
11047781104778
Anchor
11047791104779
Anchor
11047801104780
Anchor
11046991104699
Anchor
11047451104745
Anchor
11047001104700
Anchor
11047011104701
Anchor
11047021104702
Anchor
11047031104703
Anchor
10981111098111
Anchor
11049191104919
Anchor
11046941104694
Anchor
10981121098112
Anchor
10981131098113
Anchor
10981141098114
Anchor
10981151098115
Anchor
10981161098116
Anchor
10981171098117
Anchor
10981181098118
Anchor
10981191098119
Anchor
10981201098120
Anchor
10981221098122
Anchor
10981241098124
Anchor
10981251098125
Anchor
10981261098126
Anchor
10981281098128
Anchor
10981291098129
Anchor
10981301098130
Anchor
11048101104810
Anchor
10981331098133
Anchor
10981341098134
Anchor
10981351098135
Anchor
11048191104819
Anchor
10981381098138
Anchor
10979401097940

...


...

Panel

...

bgColor#f0f0f0
  1. Ensure that we don’t add header field to a response with an error

...

  1.  
  2. Make sure to add header field only on HTML document.

...

  1.  

...

  1. Acquire and add a first header field block of type ‘Cookie’ and with a string value type to the connection

...

  1.  

...

  1. Set the value string value (cookie content) and the string length.

...

  1.  
  2. Acquire and add a second header field block of type ‘Server’ and with a string value type to the connection

...

  1.  

...

  1. Set the value string value (server name) and the string length.