27
27
28
28
#include <assert.h>
29
29
#include <string.h>
30
+ #include <ctype.h>
30
31
31
32
#include "core_http_client.h"
32
33
#include "core_http_client_private.h"
@@ -544,6 +545,22 @@ static void processCompleteHeader( HTTPParsingContext_t * pParsingContext );
544
545
*/
545
546
static HTTPStatus_t processHttpParserError ( const http_parser * pHttpParser );
546
547
548
+ /**
549
+ * @brief Compares at most the first n bytes of str1 and str2 without case sensitivity
550
+ * and n must be less than the actual size of either string.
551
+ *
552
+ * @param[in] str1 First string to be compared.
553
+ * @param[in] str2 Second string to be compared.
554
+ * @param[in] n The maximum number of characters to be compared.
555
+ *
556
+ * @return One of the following:
557
+ * 0 if str1 is equal to str2
558
+ * 1 if str1 is not equal to str2.
559
+ */
560
+ static int8_t caseInsensitiveStringCmp ( const char * str1 ,
561
+ const char * str2 ,
562
+ size_t n );
563
+
547
564
/*-----------------------------------------------------------*/
548
565
549
566
static uint32_t getZeroTimestampMs ( void )
@@ -553,6 +570,25 @@ static uint32_t getZeroTimestampMs( void )
553
570
554
571
/*-----------------------------------------------------------*/
555
572
573
+ static int8_t caseInsensitiveStringCmp ( const char * str1 ,
574
+ const char * str2 ,
575
+ size_t n )
576
+ {
577
+ size_t i = 0U ;
578
+
579
+ for ( i = 0U ; i < n ; i ++ )
580
+ {
581
+ if ( toupper ( str1 [ i ] ) != toupper ( str2 [ i ] ) )
582
+ {
583
+ break ;
584
+ }
585
+ }
586
+
587
+ return ( i == n ) ? 0 : 1 ;
588
+ }
589
+
590
+ /*-----------------------------------------------------------*/
591
+
556
592
static void processCompleteHeader ( HTTPParsingContext_t * pParsingContext )
557
593
{
558
594
HTTPResponse_t * pResponse = NULL ;
@@ -2237,7 +2273,7 @@ static int findHeaderFieldParserCallback( http_parser * pHttpParser,
2237
2273
/* Check whether the parsed header matches the header we are looking for. */
2238
2274
/* Each header field consists of a case-insensitive field name (RFC 7230, section 3.2). */
2239
2275
if ( ( fieldLen == pContext -> fieldLen ) &&
2240
- ( strncasecmp ( pContext -> pField , pFieldLoc , fieldLen ) == 0 ) )
2276
+ ( caseInsensitiveStringCmp ( pContext -> pField , pFieldLoc , fieldLen ) == 0 ) )
2241
2277
{
2242
2278
LogDebug ( ( "Found header field in response: "
2243
2279
"HeaderName=%.*s, HeaderLocation=0x%p" ,
0 commit comments