Host HTTP Requests Processing
159
SWRU455A – February 2017 – Revised March 2017
Copyright © 2017, Texas Instruments Incorporated
HTTP Server
{
/* Prepare pending response */
pNetAppResponse->Status = SL_NETAPP_RESPONSE_PENDING;
pNetAppResponse->ResponseData.pMetadata =
NULL
;
pNetAppResponse->ResponseData.MetadataLen = 0;
pNetAppResponse->ResponseData.pPayload =
NULL
;
pNetAppResponse->ResponseData.PayloadLen = 0;
pNetAppResponse->ResponseData.Flags = 0;
/* Copy to some global buffer any relevant info from
pNetAppRequest (the handle
In particular) and signal the user application that a new HTTP request has arrived. */
}
break
;
default
:
/* POST/PUT/DELETE requests will reach here. */
break
;
}
}
When signaled, the user application can then send this suggested response:
#define RESPONSE_TEXT "Example text part 1 --- "
#define RESPONSE_TEXT2 "Example text part 2"
_u8 *metadataBuff;
_u8 *pResponseText;
_u8 *pMetadata;
_u16 MetadataLen = 0;
const _u8 *contentType =
"text/html"
;
_u8 Flags = 0;
_u16 TextLength;
metadataBuff = (_u8 *) malloc (128);
pMetadata = metadataBuff;
/* HTTP status is sent as part of the meta-data*/
*pMetadata = (_u8) SL_NETAPP_REQUEST_METADATA_TYPE_STATUS;
pM+;
*(_u16 *)pMetadata = (_u16) 2;
pM=2;
*(_u16 *)pMetadata = (_u16) SL_NETAPP_HTTP_RESPONSE_200_OK;
pM=2;
/* Write the content type TLV to buffer */
*pMetadata = (_u8) SL_NETAPP_REQUEST_METADATA_TYPE_HTTP_CONTENT_TYPE;
pM+;
*(_u16 *)pMetadata = (_u16) strlen((char*)contentType);
pM=2;
memcpy (pMetadata, contentType, strlen((char*)contentType));
pM=strlen((char*)contentType);
/* Write the content length TLV to buffer */
*pMetadata = SL_NETAPP_REQUEST_METADATA_TYPE_HTTP_CONTENT_LEN;
pM+;
*(_u16 *)pMetadata = 2;
pM=2;
TextLength =
sizeof
(RESPONSE_TEXT) +
sizeof
(RESPONSE_TEXT2);
*(_u16 *) pMetadata = TextLength;
pM=2;
MetadataLen = pMetadata - metadataBuff;
/* First send the meta-
data (note the METADATA flag). Continuation flag indicates there are more fragments to follow.
gHandle is assumed to be populated by the handler.
*/
Flags |= SL_NETAPP_REQUEST_RESPONSE_FLAGS_CONTINUATION;