Host HTTP Requests Processing
163
SWRU455A – February 2017 – Revised March 2017
Copyright © 2017, Texas Instruments Incorporated
HTTP Server
RequestFlags = pNetAppRequest->requestData.Flags;
/* Prepare pending response */
pNetAppResponse->ResponseData.pMetadata = NULL;
pNetAppResponse->ResponseData.MetadataLen = 0;
pNetAppResponse->ResponseData.pPayload = NULL;
pNetAppResponse->ResponseData.PayloadLen = 0;
pNetAppResponse->ResponseData.Flags = 0;
if
(pNetAppRequest->requestData.MetadataLen > 0)
{
/* Process the meta data in
pNetAppRequest-
>requestData.pMetadata */
ContentLength = ExtractLengthFromMetaData(
pNetAppRequest->requestData.pMetadata,
pNetAppRequest->requestData.MetadataLen);
/* Allocate buffer to receive the entire content if needed */
}
if
(pNetAppRequest->requestData.PayloadLen > 0)
{
/* First fragment of the payload is @
pNetAppRequest-
>requestData.pPayload */
}
if
(RequestFlags & SL_NETAPP_REQUEST_RESPONSE_FLAGS_CONTINUATION)
{
/* More fragments to follow. */
pNetAppResponse->Status = SL_NETAPP_RESPONSE_PENDING;
/* Signal the user application to receive the rest.*/
SetEvent(g_netAppRequestSyncObj);
/* The handle will be used to receive the rest + send response*/
gHandle = pNetAppRequest->Handle;
}
else
{
pNetAppResponse->Status = SL_NETAPP_HTTP_RESPONSE_200_OK;
}
break
;
}
default
:
/* GET/PUT/DELETE requests will reach here. */
break
;
}
}
The following code can be placed in the user application, to retrieve the remaining fragments and send a
response in the end when signaled from the preceeding handler.
_u8 *MetadataBuff;
_u8 *pMetadata;
_u16 MetadataLen = 0;
_u8 Fragment[100];
/* Fragment buffer of arbitrary size */
_u16 FragmentLen;
_SlReturnVal_t RetVal;
_u32 Flags;
do
{
FragmentLen =
sizeof
(Fragment);
/* Indicates max buffer size */
RetVal = sl_NetAppRecv(gHandle, &FragmentLen, Fragment, &Flags);
if
((RetVal < 0) | (Flags & SL_NETAPP_REQUEST_RESPONSE_FLAGS_ERROR))
{
// API error, abort. Error code can be extracted as follows:
// ErrorCode =