Skip to end of metadata
Go to start of metadata

You are viewing an old version of this page. View the current version.

Compare with Current View Page History

« Previous Version 14 Next »

This hook function, if defined, is called by μC/HTTP-server after an HTTP request has been completely received as shown in the figure Hook Functions. It allows the upper application to do whatever wanted with data received in the request body. The hook function SHOULD NOT be blocking and SHOULD return quickly. A time consuming function will block the processing of the other connections and reduce the HTTP server performance. In case the request processing is time consuming, the Poll hook function SHOULD be enabled to allow the server to periodically verify if the upper application has finished the request processing. If the hook is not required by the upper application, it can be set as DEF_NULL and no function will be called.

Prototype

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_data

Pointer to the first control key value pair, if any form was received.
DEF_NULL, otherwise.

Return Values

DEF_YES

If the response can be sent.

DEF_NO

if the response cannot be sent after this call and Poll function MUST be called before sending the response

Required Configuration

See section Hook Configuration.

Notes / Warnings

  • The instance structure is for read-only. It must not be modified.
  • The following connection attributes can be accessed to analyze the connection (see HTTPs_CONN in Control Structures for further details on each parameters):

    • ClientAddr
    • Method
    • PathPtr
    • ReqHdrCtr
    • ReqHdrFirstPtr
    • ConnDataPtr
  • In this hook function, only the under-mentioned connection parameters are allowed to be modified (see HTTPs_CONN in Control Structures for further details on each parameters):
    • StatusCode
    • PathPtr
    • FilePtr
    • FileLen
    • BodyDataType
  • If the request data take a while to be processed:
    • The processing should be done in a separate task and not in this callback function to avoid blocking other connections.
    • The poll callback function should be used to allow the connection to poll periodically the upper application and verify if the request processing has been completed.

      Note that The ConnDataPtr attribute inside de HTTPs_CONN structure can be used to store a semaphore pointer related or anything else that can help to determine the completion of the request processing.

Example Template

The listing below is shown to demonstrate the µC/HTTP-server module capabilities. That code analyses each key value pair in the list and try to find control name which is linked to led blinking functionality and change the document returned to display the led state using a data in memory as well.

  • No labels