in source/core_http_client.c [1557:1650]
HTTPStatus_t HTTPClient_InitializeRequestHeaders( HTTPRequestHeaders_t * pRequestHeaders,
const HTTPRequestInfo_t * pRequestInfo )
{
HTTPStatus_t returnStatus = HTTPSuccess;
/* Check for NULL parameters. */
if( pRequestHeaders == NULL )
{
LogError( ( "Parameter check failed: pRequestHeaders is NULL." ) );
returnStatus = HTTPInvalidParameter;
}
else if( pRequestHeaders->pBuffer == NULL )
{
LogError( ( "Parameter check failed: pRequestHeaders->pBuffer is NULL." ) );
returnStatus = HTTPInvalidParameter;
}
else if( pRequestInfo == NULL )
{
LogError( ( "Parameter check failed: pRequestInfo is NULL." ) );
returnStatus = HTTPInvalidParameter;
}
else if( pRequestInfo->pMethod == NULL )
{
LogError( ( "Parameter check failed: pRequestInfo->pMethod is NULL." ) );
returnStatus = HTTPInvalidParameter;
}
else if( pRequestInfo->pHost == NULL )
{
LogError( ( "Parameter check failed: pRequestInfo->pHost is NULL." ) );
returnStatus = HTTPInvalidParameter;
}
else if( pRequestInfo->methodLen == 0U )
{
LogError( ( "Parameter check failed: pRequestInfo->methodLen must be greater than 0." ) );
returnStatus = HTTPInvalidParameter;
}
else if( pRequestInfo->hostLen == 0U )
{
LogError( ( "Parameter check failed: pRequestInfo->hostLen must be greater than 0." ) );
returnStatus = HTTPInvalidParameter;
}
else
{
/* Empty else MISRA 15.7 */
}
if( returnStatus == HTTPSuccess )
{
/* Reset application-provided parameters. */
pRequestHeaders->headersLen = 0U;
/* Write "<METHOD> <PATH> HTTP/1.1\r\n" to start the HTTP header. */
returnStatus = writeRequestLine( pRequestHeaders,
pRequestInfo->pMethod,
pRequestInfo->methodLen,
pRequestInfo->pPath,
pRequestInfo->pathLen );
}
if( returnStatus == HTTPSuccess )
{
/* Write "User-Agent: <Value>". */
returnStatus = addHeader( pRequestHeaders,
HTTP_USER_AGENT_FIELD,
HTTP_USER_AGENT_FIELD_LEN,
HTTP_USER_AGENT_VALUE,
HTTP_USER_AGENT_VALUE_LEN );
}
if( returnStatus == HTTPSuccess )
{
/* Write "Host: <Value>". */
returnStatus = addHeader( pRequestHeaders,
HTTP_HOST_FIELD,
HTTP_HOST_FIELD_LEN,
pRequestInfo->pHost,
pRequestInfo->hostLen );
}
if( returnStatus == HTTPSuccess )
{
if( ( HTTP_REQUEST_KEEP_ALIVE_FLAG & pRequestInfo->reqFlags ) != 0U )
{
/* Write "Connection: keep-alive". */
returnStatus = addHeader( pRequestHeaders,
HTTP_CONNECTION_FIELD,
HTTP_CONNECTION_FIELD_LEN,
HTTP_CONNECTION_KEEP_ALIVE_VALUE,
HTTP_CONNECTION_KEEP_ALIVE_VALUE_LEN );
}
}
return returnStatus;
}