Host HTTP Requests Processing
160
SWRU455A – February 2017 – Revised March 2017
Copyright © 2017, Texas Instruments Incorporated
HTTP Server
Flags |= SL_NETAPP_REQUEST_RESPONSE_FLAGS_METADATA;
sl_NetAppSend (gHandle, MetadataLen, metadataBuff, Flags);
/* Send first data fragment. Continuation flag still
indicates there are more fragments to
follow, */
Flags = SL_NETAPP_REQUEST_RESPONSE_FLAGS_CONTINUATION;
pResponseText = (_u8 *) malloc (
sizeof
(RESPONSE_TEXT));
memcpy(pResponseText, RESPONSE_TEXT,
sizeof
(RESPONSE_TEXT));
sl_NetAppSend (gHandle,
sizeof
(RESPONSE_TEXT), pResponseText, Flags);
/* Last data fragment - continuation flag is cleared. */
Flags = 0;
pResponseText = (_u8 *) malloc (
sizeof
(RESPONSE_TEXT2));
memcpy(pResponseText, RESPONSE_TEXT2,
sizeof
(RESPONSE_TEXT2));
sl_NetAppSend (gHandle,
sizeof
(RESPONSE_TEXT2), pResponseText, Flags);
9.7.3 POST Processing
POST requests that were not recognized as RESTFul APIs are transferred to the host with
SL_NETAPP_REQUEST_HTTP_POST as the request type. The user handler must parse the HTTP
metadata, extract the resource name and any other fields of interest, and generate a response. The host
may choose to respond immediately by filling all response fields in the handler. Alternatively, the host can
fill the status field to pending and return, which means another part of the user application must complete
the reception of the request using the sl_NetAppRecv API. Then it must use the sl_NetAppSend API to
send a response.
shows the data flow when the response is sent immediately.
Figure 9-12. POST Processing Flow
Similarly to
, the following code receives acknowledgments for every POST request to the host
with an HTTP 200 OK response:
void
NetAppRequestHandler(
SlNetAppRequest_t *pNetAppRequest,
SlNetAppResponse_t *pNetAppResponse)
{
extern
_u16 gHandle;
switch
(pNetAppRequest->Type)
{
case
SL_NETAPP_REQUEST_HTTP_POST:
{
pNetAppResponse->Status = SL_NETAPP_HTTP_RESPONSE_200_OK;
pNetAppResponse->ResponseData.pMetadata = NULL;
pNetAppResponse->ResponseData.MetadataLen = 0;
pNetAppResponse->ResponseData.pPayload = NULL;
pNetAppResponse->ResponseData.PayloadLen = 0;
pNetAppResponse->ResponseData.Flags = 0;