@@ -1015,8 +1015,7 @@ static void initializeParsingContextForFirstResponse( HTTPParsingContext_t * pPa
1015
1015
* indicated to stop by returning a 1 from httpParserOnHeadersCompleteCallback().
1016
1016
* If this is not done, the parser will not indicate the message is complete. */
1017
1017
if ( strncmp ( ( const char * ) ( pRequestHeaders -> pBuffer ),
1018
- HTTP_METHOD_HEAD ,
1019
- sizeof ( HTTP_METHOD_HEAD ) - 1U ) == 0 )
1018
+ HTTP_METHOD_HEAD , CONST_STRLEN ( HTTP_METHOD_HEAD ) ) == 0 )
1020
1019
{
1021
1020
pParsingContext -> isHeadResponse = 1U ;
1022
1021
}
@@ -1327,18 +1326,19 @@ static HTTPStatus_t addHeader( HTTPRequestHeaders_t * pRequestHeaders,
1327
1326
/* Backtrack before trailing "\r\n" (HTTP header end) if it's already written.
1328
1327
* Note that this method also writes trailing "\r\n" before returning.
1329
1328
* The first condition prevents reading before start of the header. */
1330
- if ( ( 4U <= pRequestHeaders -> headersLen ) &&
1331
- ( strcmp ( "\r\n\r\n" , ( char * ) pBufferCur - 4U ) == 0 ) )
1329
+ if ( ( CONST_STRLEN ( "\r\n\r\n" ) <= pRequestHeaders -> headersLen ) &&
1330
+ ( strcmp ( "\r\n\r\n" , ( char * ) pBufferCur - CONST_STRLEN ( "\r\n\r\n" ) ) == 0 ) )
1332
1331
{
1333
- backtrackHeaderLen -= 2U ;
1334
- pBufferCur -= 2U ;
1332
+ backtrackHeaderLen -= CONST_STRLEN ( "\r\n" ) ;
1333
+ pBufferCur -= CONST_STRLEN ( "\r\n" ) ;
1335
1334
}
1336
1335
1337
1336
/*
1338
1337
* Check if there is enough space in buffer for additional header.
1339
1338
* "<field>: <value>\r\n\r\n"
1340
1339
*/
1341
- toAddLen = fieldLen + 2U + valueLen + 2U + 2U ;
1340
+ toAddLen = fieldLen + CONST_STRLEN ( ": " ) +
1341
+ valueLen + CONST_STRLEN ( "\r\n\r\n" );
1342
1342
1343
1343
/* If we have enough room for the new header line, then write it to the
1344
1344
* header buffer. */
@@ -1359,7 +1359,7 @@ static HTTPStatus_t addHeader( HTTPRequestHeaders_t * pRequestHeaders,
1359
1359
/* Copy the field separator, ": ", into the buffer. */
1360
1360
( void ) strcpy ( pBufferCur , ": " );
1361
1361
1362
- pBufferCur += 2U ;
1362
+ pBufferCur += CONST_STRLEN ( ": " ) ;
1363
1363
1364
1364
/* Copy the header value into the buffer. */
1365
1365
if ( httpHeaderStrncpy ( pBufferCur , pValue , valueLen , HTTP_HEADER_STRNCPY_IS_VALUE ) == NULL )
@@ -1414,7 +1414,7 @@ static HTTPStatus_t addRangeHeader( HTTPRequestHeaders_t * pRequestHeaders,
1414
1414
/* Write the range value prefix in the buffer. */
1415
1415
( void ) strcpy ( rangeValueBuffer , "bytes=" );
1416
1416
1417
- rangeValueLength += sizeof ( "bytes=" ) - 1U ;
1417
+ rangeValueLength += CONST_STRLEN ( "bytes=" );
1418
1418
1419
1419
/* Write the range start value in the buffer. */
1420
1420
rangeValueLength += convertInt32ToAscii ( rangeStartOrlastNbytes ,
@@ -1450,7 +1450,7 @@ static HTTPStatus_t addRangeHeader( HTTPRequestHeaders_t * pRequestHeaders,
1450
1450
/* Add the Range Request header field and value to the buffer. */
1451
1451
returnStatus = addHeader ( pRequestHeaders ,
1452
1452
"Range" ,
1453
- sizeof ( "Range" ) - 1U ,
1453
+ CONST_STRLEN ( "Range" ),
1454
1454
rangeValueBuffer ,
1455
1455
rangeValueLength );
1456
1456
@@ -1477,16 +1477,15 @@ static HTTPStatus_t writeRequestLine( HTTPRequestHeaders_t * pRequestHeaders,
1477
1477
if ( ( pPath == NULL ) || ( pathLen == 0U ) )
1478
1478
{
1479
1479
/* "<METHOD> / " */
1480
- toAddLen = methodLen + 1U + 1U + 1U ;
1480
+ toAddLen = methodLen + CONST_STRLEN ( " / " ) ;
1481
1481
}
1482
1482
else
1483
1483
{
1484
1484
/* "<METHOD> <PATH> " */
1485
1485
toAddLen = methodLen + 1U + pathLen + 1U ;
1486
1486
}
1487
1487
1488
- /* "HTTP/1.1\r\n" */
1489
- toAddLen += sizeof ( "HTTP/1.1" ) - 1U + 2U ;
1488
+ toAddLen += CONST_STRLEN ( "HTTP/1.1\r\n" );
1490
1489
1491
1490
pBufferCur = ( char * ) ( pRequestHeaders -> pBuffer );
1492
1491
@@ -1520,7 +1519,7 @@ static HTTPStatus_t writeRequestLine( HTTPRequestHeaders_t * pRequestHeaders,
1520
1519
pBufferCur += 1U ;
1521
1520
1522
1521
( void ) strcpy ( pBufferCur , "HTTP/1.1\r\n" );
1523
- pBufferCur += sizeof ( "HTTP/1.1\r\n" ) - 1U ;
1522
+ pBufferCur += CONST_STRLEN ( "HTTP/1.1\r\n" );
1524
1523
1525
1524
pRequestHeaders -> headersLen = toAddLen ;
1526
1525
}
@@ -1594,17 +1593,17 @@ HTTPStatus_t HTTPClient_InitializeRequestHeaders( HTTPRequestHeaders_t * pReques
1594
1593
/* Write "User-Agent: <Value>". */
1595
1594
returnStatus = addHeader ( pRequestHeaders ,
1596
1595
"User-Agent" ,
1597
- sizeof ( "User-Agent" ) - 1U ,
1596
+ CONST_STRLEN ( "User-Agent" ),
1598
1597
HTTP_USER_AGENT_VALUE ,
1599
- sizeof ( HTTP_USER_AGENT_VALUE ) - 1U );
1598
+ CONST_STRLEN ( HTTP_USER_AGENT_VALUE ) );
1600
1599
}
1601
1600
1602
1601
if ( returnStatus == HTTPSuccess )
1603
1602
{
1604
1603
/* Write "Host: <Value>". */
1605
1604
returnStatus = addHeader ( pRequestHeaders ,
1606
1605
"Host" ,
1607
- sizeof ( "Host" ) - 1U ,
1606
+ CONST_STRLEN ( "Host" ),
1608
1607
pRequestInfo -> pHost ,
1609
1608
pRequestInfo -> hostLen );
1610
1609
}
@@ -1616,9 +1615,9 @@ HTTPStatus_t HTTPClient_InitializeRequestHeaders( HTTPRequestHeaders_t * pReques
1616
1615
/* Write "Connection: keep-alive". */
1617
1616
returnStatus = addHeader ( pRequestHeaders ,
1618
1617
"Connection" ,
1619
- sizeof ( "Connection" ) - 1U ,
1618
+ CONST_STRLEN ( "Connection" ),
1620
1619
"keep-alive" ,
1621
- sizeof ( "keep-alive" ) - 1U );
1620
+ CONST_STRLEN ( "keep-alive" ) );
1622
1621
}
1623
1622
}
1624
1623
@@ -1848,7 +1847,7 @@ static HTTPStatus_t addContentLengthHeader( HTTPRequestHeaders_t * pRequestHeade
1848
1847
1849
1848
returnStatus = addHeader ( pRequestHeaders ,
1850
1849
"Content-Length" ,
1851
- sizeof ( "Content-Length" ) - 1U ,
1850
+ CONST_STRLEN ( "Content-Length" ),
1852
1851
pContentLengthValue ,
1853
1852
contentLengthValueNumBytes );
1854
1853
@@ -1871,18 +1870,15 @@ static HTTPStatus_t sendHttpHeaders( const TransportInterface_t * pTransport,
1871
1870
uint32_t sendFlags )
1872
1871
{
1873
1872
HTTPStatus_t returnStatus = HTTPSuccess ;
1874
- uint8_t shouldSendContentLength = 0U ;
1875
1873
1876
1874
assert ( pTransport != NULL );
1877
1875
assert ( pTransport -> send != NULL );
1878
1876
assert ( pRequestHeaders != NULL );
1879
1877
1880
1878
/* Send the content length header if the flag to disable is not set and the
1881
1879
* body length is greater than zero. */
1882
- shouldSendContentLength = ( ( ( sendFlags & HTTP_SEND_DISABLE_CONTENT_LENGTH_FLAG ) == 0U ) &&
1883
- ( reqBodyLen > 0U ) ) ? 1U : 0U ;
1884
-
1885
- if ( shouldSendContentLength == 1U )
1880
+ if ( ( reqBodyLen > 0U ) &&
1881
+ ( ( sendFlags & HTTP_SEND_DISABLE_CONTENT_LENGTH_FLAG ) == 0U ) )
1886
1882
{
1887
1883
returnStatus = addContentLengthHeader ( pRequestHeaders , reqBodyLen );
1888
1884
}
0 commit comments