From d834a62daedb3ab8dc28be135e2cc8e96794d63f Mon Sep 17 00:00:00 2001 From: Paul Bartell Date: Tue, 2 Aug 2022 11:03:07 -0700 Subject: [PATCH] Improve readability by removing #defined strings --- source/core_http_client.c | 106 +++++++++++----------- source/include/core_http_client.h | 2 +- source/include/core_http_client_private.h | 95 ++----------------- test/unit-test/core_http_send_utest.c | 100 ++++++++++---------- test/unit-test/core_http_utest.c | 102 ++++++++++----------- 5 files changed, 161 insertions(+), 244 deletions(-) diff --git a/source/core_http_client.c b/source/core_http_client.c index 9bcfdf3e..a3a36557 100644 --- a/source/core_http_client.c +++ b/source/core_http_client.c @@ -1268,19 +1268,19 @@ static char * httpHeaderStrncpy( char * pDest, for( ; i < len; i++ ) { - if( pSrc[ i ] == CARRIAGE_RETURN_CHARACTER ) + if( pSrc[ i ] == '\r' ) { LogError( ( "Invalid character '\r' found in %.*s", ( int ) len, pSrc ) ); hasError = 1U; } - else if( pSrc[ i ] == LINEFEED_CHARACTER ) + else if( pSrc[ i ] == '\n' ) { LogError( ( "Invalid character '\n' found in %.*s", ( int ) len, pSrc ) ); hasError = 1U; } - else if( ( isField == 1U ) && ( pSrc[ i ] == COLON_CHARACTER ) ) + else if( ( isField == 1U ) && ( pSrc[ i ] == ':' ) ) { LogError( ( "Invalid character ':' found in %.*s", ( int ) len, pSrc ) ); @@ -1327,18 +1327,18 @@ static HTTPStatus_t addHeader( HTTPRequestHeaders_t * pRequestHeaders, /* Backtrack before trailing "\r\n" (HTTP header end) if it's already written. * Note that this method also writes trailing "\r\n" before returning. * The first condition prevents reading before start of the header. */ - if( ( HTTP_HEADER_END_INDICATOR_LEN <= pRequestHeaders->headersLen ) && - ( strncmp( ( char * ) pBufferCur - HTTP_HEADER_END_INDICATOR_LEN, - HTTP_HEADER_END_INDICATOR, HTTP_HEADER_END_INDICATOR_LEN ) == 0 ) ) + if( ( 4U <= pRequestHeaders->headersLen ) && + ( strncmp( ( char * ) pBufferCur - 4U, + "\r\n\r\n", 4U ) == 0 ) ) { - backtrackHeaderLen -= HTTP_HEADER_LINE_SEPARATOR_LEN; - pBufferCur -= HTTP_HEADER_LINE_SEPARATOR_LEN; + backtrackHeaderLen -= 2U; + pBufferCur -= 2U; } /* Check if there is enough space in buffer for additional header. */ - toAddLen = fieldLen + HTTP_HEADER_FIELD_SEPARATOR_LEN + valueLen + - HTTP_HEADER_LINE_SEPARATOR_LEN + - HTTP_HEADER_LINE_SEPARATOR_LEN; + toAddLen = fieldLen + 2U + valueLen + + 2U + + 2U; /* If we have enough room for the new header line, then write it to the * header buffer. */ @@ -1358,10 +1358,10 @@ static HTTPStatus_t addHeader( HTTPRequestHeaders_t * pRequestHeaders, /* Copy the field separator, ": ", into the buffer. */ ( void ) memcpy( pBufferCur, - HTTP_HEADER_FIELD_SEPARATOR, - HTTP_HEADER_FIELD_SEPARATOR_LEN ); + ": ", + 2U ); - pBufferCur += HTTP_HEADER_FIELD_SEPARATOR_LEN; + pBufferCur += 2U; /* Copy the header value into the buffer. */ if( httpHeaderStrncpy( pBufferCur, pValue, valueLen, HTTP_HEADER_STRNCPY_IS_VALUE ) == NULL ) @@ -1376,8 +1376,8 @@ static HTTPStatus_t addHeader( HTTPRequestHeaders_t * pRequestHeaders, /* Copy the header end indicator, "\r\n\r\n" into the buffer. */ ( void ) memcpy( pBufferCur, - HTTP_HEADER_END_INDICATOR, - HTTP_HEADER_END_INDICATOR_LEN ); + "\r\n\r\n", + 4U ); /* Update the headers length value only when everything is successful. */ pRequestHeaders->headersLen = backtrackHeaderLen + toAddLen; @@ -1417,9 +1417,9 @@ static HTTPStatus_t addRangeHeader( HTTPRequestHeaders_t * pRequestHeaders, /* Write the range value prefix in the buffer. */ ( void ) strncpy( rangeValueBuffer, - HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX, - HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN ); - rangeValueLength += HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN; + "bytes=", + sizeof( "bytes=" ) - 1U ); + rangeValueLength += sizeof( "bytes=" ) - 1U; /* Write the range start value in the buffer. */ rangeValueLength += convertInt32ToAscii( rangeStartOrlastNbytes, @@ -1432,8 +1432,8 @@ static HTTPStatus_t addRangeHeader( HTTPRequestHeaders_t * pRequestHeaders, if( rangeEnd != HTTP_RANGE_REQUEST_END_OF_FILE ) { /* Write the "-" character to the buffer.*/ - *( rangeValueBuffer + rangeValueLength ) = DASH_CHARACTER; - rangeValueLength += DASH_CHARACTER_LEN; + *( rangeValueBuffer + rangeValueLength ) = '-'; + rangeValueLength += 1U; /* Write the rangeEnd value of the request range to the buffer. */ rangeValueLength += convertInt32ToAscii( rangeEnd, @@ -1444,8 +1444,8 @@ static HTTPStatus_t addRangeHeader( HTTPRequestHeaders_t * pRequestHeaders, else if( rangeStartOrlastNbytes >= 0 ) { /* Write the "-" character to the buffer.*/ - *( rangeValueBuffer + rangeValueLength ) = DASH_CHARACTER; - rangeValueLength += DASH_CHARACTER_LEN; + *( rangeValueBuffer + rangeValueLength ) = '-'; + rangeValueLength += 1U; } else { @@ -1454,8 +1454,8 @@ static HTTPStatus_t addRangeHeader( HTTPRequestHeaders_t * pRequestHeaders, /* Add the Range Request header field and value to the buffer. */ returnStatus = addHeader( pRequestHeaders, - HTTP_RANGE_REQUEST_HEADER_FIELD, - HTTP_RANGE_REQUEST_HEADER_FIELD_LEN, + "Range", + sizeof( "Range" ) - 1U, rangeValueBuffer, rangeValueLength ); @@ -1480,13 +1480,13 @@ static HTTPStatus_t writeRequestLine( HTTPRequestHeaders_t * pRequestHeaders, assert( methodLen != 0U ); toAddLen = methodLen + \ - SPACE_CHARACTER_LEN + \ - SPACE_CHARACTER_LEN + \ - HTTP_PROTOCOL_VERSION_LEN + \ - HTTP_HEADER_LINE_SEPARATOR_LEN; + 1U + \ + 1U + \ + sizeof( "HTTP/1.1" ) - 1U + \ + 2U; pBufferCur = ( char * ) ( pRequestHeaders->pBuffer ); - toAddLen += ( ( pPath == NULL ) || ( pathLen == 0U ) ) ? HTTP_EMPTY_PATH_LEN : pathLen; + toAddLen += ( ( pPath == NULL ) || ( pathLen == 0U ) ) ? 1U : pathLen; if( ( toAddLen + pRequestHeaders->headersLen ) > pRequestHeaders->bufferLen ) { @@ -1499,16 +1499,16 @@ static HTTPStatus_t writeRequestLine( HTTPRequestHeaders_t * pRequestHeaders, ( void ) strncpy( pBufferCur, pMethod, methodLen ); pBufferCur += methodLen; - *pBufferCur = SPACE_CHARACTER; - pBufferCur += SPACE_CHARACTER_LEN; + *pBufferCur = ' '; + pBufferCur += 1U; /* Use "/" as default value if is NULL. */ if( ( pPath == NULL ) || ( pathLen == 0U ) ) { ( void ) strncpy( pBufferCur, - HTTP_EMPTY_PATH, - HTTP_EMPTY_PATH_LEN ); - pBufferCur += HTTP_EMPTY_PATH_LEN; + "/", + 1U ); + pBufferCur += 1U; } else { @@ -1516,17 +1516,17 @@ static HTTPStatus_t writeRequestLine( HTTPRequestHeaders_t * pRequestHeaders, pBufferCur += pathLen; } - *pBufferCur = SPACE_CHARACTER; - pBufferCur += SPACE_CHARACTER_LEN; + *pBufferCur = ' '; + pBufferCur += 1U; ( void ) strncpy( pBufferCur, - HTTP_PROTOCOL_VERSION, - HTTP_PROTOCOL_VERSION_LEN ); - pBufferCur += HTTP_PROTOCOL_VERSION_LEN; + "HTTP/1.1", + sizeof( "HTTP/1.1" ) - 1U ); + pBufferCur += sizeof( "HTTP/1.1" ) - 1U; ( void ) memcpy( pBufferCur, - HTTP_HEADER_LINE_SEPARATOR, - HTTP_HEADER_LINE_SEPARATOR_LEN ); + "\r\n", + 2U ); pRequestHeaders->headersLen = toAddLen; } @@ -1598,18 +1598,18 @@ HTTPStatus_t HTTPClient_InitializeRequestHeaders( HTTPRequestHeaders_t * pReques { /* Write "User-Agent: ". */ returnStatus = addHeader( pRequestHeaders, - HTTP_USER_AGENT_FIELD, - HTTP_USER_AGENT_FIELD_LEN, + "User-Agent", + sizeof( "User-Agent" ) - 1U, HTTP_USER_AGENT_VALUE, - HTTP_USER_AGENT_VALUE_LEN ); + sizeof( HTTP_USER_AGENT_VALUE ) - 1U ); } if( returnStatus == HTTPSuccess ) { /* Write "Host: ". */ returnStatus = addHeader( pRequestHeaders, - HTTP_HOST_FIELD, - HTTP_HOST_FIELD_LEN, + "Host", + sizeof( "Host" ) - 1U, pRequestInfo->pHost, pRequestInfo->hostLen ); } @@ -1620,10 +1620,10 @@ HTTPStatus_t HTTPClient_InitializeRequestHeaders( HTTPRequestHeaders_t * pReques { /* 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 ); + "Connection", + sizeof( "Connection" ) - 1U, + "keep-alive", + sizeof( "keep-alive" ) - 1U ); } } @@ -1852,8 +1852,8 @@ static HTTPStatus_t addContentLengthHeader( HTTPRequestHeaders_t * pRequestHeade sizeof( pContentLengthValue ) ); returnStatus = addHeader( pRequestHeaders, - HTTP_CONTENT_LENGTH_FIELD, - HTTP_CONTENT_LENGTH_FIELD_LEN, + "Content-Length", + sizeof( "Content-Length" ) - 1U, pContentLengthValue, contentLengthValueNumBytes ); diff --git a/source/include/core_http_client.h b/source/include/core_http_client.h index 6ccb05e7..addd263e 100644 --- a/source/include/core_http_client.h +++ b/source/include/core_http_client.h @@ -534,7 +534,7 @@ typedef struct HTTPResponse * of bytes written. * * Each line in the header is listed below and written in this order: - * <#HTTPRequestInfo_t.pMethod> <#HTTPRequestInfo_t.pPath> <#HTTP_PROTOCOL_VERSION> + * <#HTTPRequestInfo_t.pMethod> <#HTTPRequestInfo_t.pPath> HTTP/1.1 * User-Agent: <#HTTP_USER_AGENT_VALUE> * Host: <#HTTPRequestInfo_t.pHost> * diff --git a/source/include/core_http_client_private.h b/source/include/core_http_client_private.h index fc2ac28b..82f4953d 100644 --- a/source/include/core_http_client_private.h +++ b/source/include/core_http_client_private.h @@ -46,107 +46,24 @@ #endif /* *INDENT-ON* */ -/** - * @brief The HTTP protocol version of this library is HTTP/1.1. - */ -#define HTTP_PROTOCOL_VERSION "HTTP/1.1" -#define HTTP_PROTOCOL_VERSION_LEN ( sizeof( HTTP_PROTOCOL_VERSION ) - 1U ) /**< The length of #HTTP_PROTOCOL_VERSION. */ - -/** - * @brief Default value when pRequestInfo->pPath == NULL. - */ -#define HTTP_EMPTY_PATH "/" -#define HTTP_EMPTY_PATH_LEN ( sizeof( HTTP_EMPTY_PATH ) - 1U ) /**< The length of #HTTP_EMPTY_PATH. */ - -/* Constants for HTTP header formatting. */ -#define HTTP_HEADER_LINE_SEPARATOR "\r\n" /**< HTTP header field lines are separated by `\r\n`. */ -#define HTTP_HEADER_LINE_SEPARATOR_LEN ( sizeof( HTTP_HEADER_LINE_SEPARATOR ) - 1U ) /**< The length of #HTTP_HEADER_LINE_SEPARATOR. */ -#define HTTP_HEADER_END_INDICATOR "\r\n\r\n" /**< The HTTP header is complete when `\r\n\r\n` is found. */ -#define HTTP_HEADER_END_INDICATOR_LEN ( sizeof( HTTP_HEADER_END_INDICATOR ) - 1U ) /**< The length of #HTTP_HEADER_END_INDICATOR. */ -#define HTTP_HEADER_FIELD_SEPARATOR ": " /**< HTTP header field and values are separated by ": ". */ -#define HTTP_HEADER_FIELD_SEPARATOR_LEN ( sizeof( HTTP_HEADER_FIELD_SEPARATOR ) - 1U ) /**< The length of #HTTP_HEADER_FIELD_SEPARATOR. */ -#define SPACE_CHARACTER ' ' /**< A space character macro to help with serializing a request. */ -#define SPACE_CHARACTER_LEN ( 1U ) /**< The length of #SPACE_CHARACTER. */ -#define DASH_CHARACTER '-' /**< A dash character macro to help with serializing a request. */ -#define DASH_CHARACTER_LEN ( 1U ) /**< The length of #DASH_CHARACTER. */ - -/* Constants for HTTP header copy checks. */ -#define CARRIAGE_RETURN_CHARACTER '\r' /**< A carriage return character to help with header validation. */ -#define LINEFEED_CHARACTER '\n' /**< A linefeed character to help with header validation. */ -#define COLON_CHARACTER ':' /**< A colon character to help with header validation. */ - /** * @brief Indicator for function #httpHeaderStrncpy that the pSrc parameter is a * header value. */ -#define HTTP_HEADER_STRNCPY_IS_VALUE 0U +#define HTTP_HEADER_STRNCPY_IS_VALUE 0U /** * @brief Indicator for function #httpHeaderStrncpy that the pSrc parameter is a * header field. */ -#define HTTP_HEADER_STRNCPY_IS_FIELD 1U - -/* Constants for header fields added automatically during the request - * initialization. */ -#define HTTP_USER_AGENT_FIELD "User-Agent" /**< HTTP header field "User-Agent". */ -#define HTTP_USER_AGENT_FIELD_LEN ( sizeof( HTTP_USER_AGENT_FIELD ) - 1U ) /**< The length of #HTTP_USER_AGENT_FIELD. */ -#define HTTP_HOST_FIELD "Host" /**< HTTP header field "Host". */ -#define HTTP_HOST_FIELD_LEN ( sizeof( HTTP_HOST_FIELD ) - 1U ) /**< The length of #HTTP_HOST_FIELD. */ -#define HTTP_USER_AGENT_VALUE_LEN ( sizeof( HTTP_USER_AGENT_VALUE ) - 1U ) /**< The length of #HTTP_USER_AGENT_VALUE. */ - -/* Constants for header fields added based on flags. */ -#define HTTP_CONNECTION_FIELD "Connection" /**< HTTP header field "Connection". */ -#define HTTP_CONNECTION_FIELD_LEN ( sizeof( HTTP_CONNECTION_FIELD ) - 1U ) /**< The length of #HTTP_CONNECTION_FIELD. */ -#define HTTP_CONTENT_LENGTH_FIELD "Content-Length" /**< HTTP header field "Content-Length". */ -#define HTTP_CONTENT_LENGTH_FIELD_LEN ( sizeof( HTTP_CONTENT_LENGTH_FIELD ) - 1U ) /**< The length of #HTTP_CONTENT_LENGTH_FIELD. */ - -/* Constants for header values added based on flags. */ - -/* MISRA Rule 5.4 flags the following macro's name as ambiguous from the - * one postfixed with _LEN. This rule is suppressed for naming consistency with - * other HTTP header field and value string and length macros in this file.*/ -/* coverity[other_declaration] */ -#define HTTP_CONNECTION_KEEP_ALIVE_VALUE "keep-alive" /**< HTTP header value "keep-alive" for the "Connection" header field. */ - -/* MISRA Rule 5.4 flags the following macro's name as ambiguous from the one - * above it. This rule is suppressed for naming consistency with other HTTP - * header field and value string and length macros in this file.*/ -/* coverity[misra_c_2012_rule_5_4_violation] */ -#define HTTP_CONNECTION_KEEP_ALIVE_VALUE_LEN ( sizeof( HTTP_CONNECTION_KEEP_ALIVE_VALUE ) - 1U ) /**< The length of #HTTP_CONNECTION_KEEP_ALIVE_VALUE. */ - -/* Constants relating to Range Requests. */ - -/* MISRA Rule 5.4 flags the following macro's name as ambiguous from the - * one postfixed with _LEN. This rule is suppressed for naming consistency with - * other HTTP header field and value string and length macros in this file.*/ -/* coverity[other_declaration] */ -#define HTTP_RANGE_REQUEST_HEADER_FIELD "Range" /**< HTTP header field "Range". */ - -/* MISRA Rule 5.4 flags the following macro's name as ambiguous from the one - * above it. This rule is suppressed for naming consistency with other HTTP - * header field and value string and length macros in this file.*/ -/* coverity[misra_c_2012_rule_5_4_violation] */ -#define HTTP_RANGE_REQUEST_HEADER_FIELD_LEN ( sizeof( HTTP_RANGE_REQUEST_HEADER_FIELD ) - 1U ) /**< The length of #HTTP_RANGE_REQUEST_HEADER_FIELD. */ - -/* MISRA Rule 5.4 flags the following macro's name as ambiguous from the - * one postfixed with _LEN. This rule is suppressed for naming consistency with - * other HTTP header field and value string and length macros in this file.*/ -/* coverity[other_declaration] */ -#define HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX "bytes=" /**< HTTP required header value prefix when specifying a byte range for partial content. */ - -/* MISRA Rule 5.4 flags the following macro's name as ambiguous from the one - * above it. This rule is suppressed for naming consistency with other HTTP - * header field and value string and length macros in this file.*/ -/* coverity[misra_c_2012_rule_5_4_violation] */ -#define HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN ( sizeof( HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX ) - 1U ) /**< The length of #HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX. */ +#define HTTP_HEADER_STRNCPY_IS_FIELD 1U /** * @brief Maximum value of a 32 bit signed integer is 2,147,483,647. * * Used for calculating buffer space for ASCII representation of range values. */ -#define MAX_INT32_NO_OF_DECIMAL_DIGITS 10U +#define MAX_INT32_NO_OF_DECIMAL_DIGITS 10U /** * @brief Maximum buffer space for storing a Range Request Value. @@ -154,9 +71,9 @@ * The largest Range Request value is of the form: * "bytes=-" */ -#define HTTP_MAX_RANGE_REQUEST_VALUE_LEN \ - ( HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN + MAX_INT32_NO_OF_DECIMAL_DIGITS + \ - 1U /* Dash character '-' */ + MAX_INT32_NO_OF_DECIMAL_DIGITS ) +#define HTTP_MAX_RANGE_REQUEST_VALUE_LEN \ + ( sizeof( "bytes=" ) - 1U + MAX_INT32_NO_OF_DECIMAL_DIGITS + \ + 1U + MAX_INT32_NO_OF_DECIMAL_DIGITS ) /** * @brief Return value for llhttp registered callback to signal diff --git a/test/unit-test/core_http_send_utest.c b/test/unit-test/core_http_send_utest.c index 4ae0ae78..90fb1e86 100644 --- a/test/unit-test/core_http_send_utest.c +++ b/test/unit-test/core_http_send_utest.c @@ -57,7 +57,7 @@ #define HTTP_TEST_REQUEST_PUT_HEADERS_LENGTH ( sizeof( HTTP_TEST_REQUEST_PUT_HEADERS ) - 1U ) #define HTTP_TEST_REQUEST_PUT_BODY "abcdefghijklmnopqrstuvwxyz" #define HTTP_TEST_REQUEST_PUT_BODY_LENGTH ( sizeof( HTTP_TEST_REQUEST_PUT_BODY ) - 1U ) -#define HTTP_TEST_REQUEST_PUT_CONTENT_LENGTH_EXPECTED "Content-Length: 26\r\n" HTTP_HEADER_LINE_SEPARATOR +#define HTTP_TEST_REQUEST_PUT_CONTENT_LENGTH_EXPECTED "Content-Length: 26\r\n" "\r\n" #define HTTP_TEST_REQUEST_PUT_CONTENT_LENGTH_EXPECTED_LENGTH ( sizeof( HTTP_TEST_REQUEST_PUT_CONTENT_LENGTH_EXPECTED ) - 1U ) /* Template HTTP request for a GET request. */ @@ -100,7 +100,7 @@ HTTP_TEST_ETAG_HEADER_LINE \ HTTP_TEST_VARY_HEADER_LINE \ HTTP_TEST_P3P_HEADER_LINE \ - HTTP_TEST_XSERVER_HEADER_LINE HTTP_HEADER_LINE_SEPARATOR + HTTP_TEST_XSERVER_HEADER_LINE "\r\n" #define HTTP_TEST_RESPONSE_HEAD_LENGTH ( sizeof( HTTP_TEST_RESPONSE_HEAD ) - 1U ) #define HTTP_TEST_RESPONSE_HEAD_HEADER_COUNT 7 #define HTTP_TEST_RESPONSE_HEAD_CONTENT_LENGTH 43 @@ -115,7 +115,7 @@ HTTP_TEST_ETAG_HEADER_LINE \ HTTP_TEST_VARY_HEADER_LINE \ HTTP_TEST_P3P_HEADER_LINE \ - HTTP_TEST_XSERVER_HEADER_LINE HTTP_HEADER_LINE_SEPARATOR + HTTP_TEST_XSERVER_HEADER_LINE "\r\n" #define HTTP_TEST_RESPONSE_PUT_LENGTH ( sizeof( HTTP_TEST_RESPONSE_PUT ) - 1U ) #define HTTP_TEST_RESPONSE_PUT_HEADER_COUNT 6 @@ -131,23 +131,23 @@ #define HTTP_TEST_RESPONSE_GET_PARTIAL_BODY_LENGTH ( HTTP_TEST_RESPONSE_GET_LENGTH - 13U ) /* Template HTTP transfer-encoding chunked response. */ -#define HTTP_TEST_RESPONSE_CHUNKED \ - HTTP_STATUS_LINE_OK \ - HTTP_TEST_TRANSFER_ENCODING_CHUNKED_HEADER_LINE \ - HTTP_TEST_CONNECTION_KEEP_ALIVE_HEADER_LINE \ - HTTP_TEST_DATE_HEADER_LINE \ - HTTP_TEST_ETAG_HEADER_LINE \ - HTTP_TEST_VARY_HEADER_LINE \ - HTTP_TEST_P3P_HEADER_LINE \ - HTTP_TEST_XSERVER_HEADER_LINE HTTP_HEADER_LINE_SEPARATOR \ - "b\r\n" \ - "abcdefghijk\r\n" \ - "c\r\n" \ - "lmnopqrstuvw\r\n" \ - "3\r\n" \ - "xyz\r\n" \ - "0\r\n" \ - "\r\n" +#define HTTP_TEST_RESPONSE_CHUNKED \ + HTTP_STATUS_LINE_OK \ + HTTP_TEST_TRANSFER_ENCODING_CHUNKED_HEADER_LINE \ + HTTP_TEST_CONNECTION_KEEP_ALIVE_HEADER_LINE \ + HTTP_TEST_DATE_HEADER_LINE \ + HTTP_TEST_ETAG_HEADER_LINE \ + HTTP_TEST_VARY_HEADER_LINE \ + HTTP_TEST_P3P_HEADER_LINE \ + HTTP_TEST_XSERVER_HEADER_LINE "\r\n" \ + "b\r\n" \ + "abcdefghijk\r\n" \ + "c\r\n" \ + "lmnopqrstuvw\r\n" \ + "3\r\n" \ + "xyz\r\n" \ + "0\r\n" \ + "\r\n" #define HTTP_TEST_RESPONSE_CHUNKED_LENGTH ( sizeof( HTTP_TEST_RESPONSE_CHUNKED ) - 1U ) #define HTTP_TEST_RESPONSE_CHUNKED_HEADER_COUNT 7 #define HTTP_TEST_RESPONSE_CHUNKED_BODY_LENGTH 26 @@ -159,11 +159,11 @@ sizeof( HTTP_TEST_VARY_HEADER_LINE ) + \ sizeof( HTTP_TEST_P3P_HEADER_LINE ) + \ sizeof( HTTP_TEST_XSERVER_HEADER_LINE ) + \ - HTTP_HEADER_LINE_SEPARATOR_LEN - 7U + 2U - 7U /* Template HTTP response with no headers. */ #define HTTP_TEST_RESPONSE_NO_HEADERS \ - HTTP_STATUS_LINE_OK HTTP_HEADER_LINE_SEPARATOR + HTTP_STATUS_LINE_OK "\r\n" #define HTTP_TEST_RESPONSE_NO_HEADERS_LENGTH ( sizeof( HTTP_TEST_RESPONSE_NO_HEADERS ) - 1U ) /* Test buffer to share among the test. */ @@ -436,19 +436,19 @@ static void helper_parse_status_line( const char ** pNext, * cases, so the reason-phrase is always after HTTP/1.1 and the three digit * status code. strchr() is used only for unit testing where test input are * always string literals. strchr() should not be used in application code. */ - *pNext = strchr( *pNext, SPACE_CHARACTER ); /* Get the space before the status-code. */ - *pNext += SPACE_CHARACTER_LEN; - *pNext = strchr( *pNext, SPACE_CHARACTER ); /* Get the space before the reason-phrase. */ - *pNext += SPACE_CHARACTER_LEN; + *pNext = strchr( *pNext, ' ' ); /* Get the space before the status-code. */ + *pNext += 1U; + *pNext = strchr( *pNext, ' ' ); /* Get the space before the reason-phrase. */ + *pNext += 1U; pReasonPhraseStart = *pNext; - *pNext = strstr( *pNext, HTTP_HEADER_LINE_SEPARATOR ); + *pNext = strstr( *pNext, "\r\n" ); reasonPhraseStartLen = ( size_t ) ( *pNext - pReasonPhraseStart ); pParser->status_code = 200; pSettings->on_status( pParser, pReasonPhraseStart, reasonPhraseStartLen ); - *pNext += HTTP_HEADER_LINE_SEPARATOR_LEN; + *pNext += 2U; } /* Mock helper that parses all of the headers starting from pNext. */ @@ -464,18 +464,18 @@ static void helper_parse_headers( const char ** pNext, while( **pNext != '\r' ) { pHeaderFieldStart = *pNext; - *pNext = strstr( *pNext, HTTP_HEADER_FIELD_SEPARATOR ); + *pNext = strstr( *pNext, ": " ); headerFieldLen = ( size_t ) ( *pNext - pHeaderFieldStart ); pSettings->on_header_field( pParser, pHeaderFieldStart, headerFieldLen ); - *pNext += HTTP_HEADER_FIELD_SEPARATOR_LEN; + *pNext += 2U; pHeaderValueStart = *pNext; - *pNext = strstr( *pNext, HTTP_HEADER_LINE_SEPARATOR ); + *pNext = strstr( *pNext, "\r\n" ); headerValueLen = ( size_t ) ( *pNext - pHeaderValueStart ); pSettings->on_header_value( pParser, pHeaderValueStart, headerValueLen ); - *pNext += HTTP_HEADER_LINE_SEPARATOR_LEN; + *pNext += 2U; } } @@ -507,7 +507,7 @@ static void helper_parse_headers_finish( const char ** pNext, *isHeadResponse = isHeadResponseReturned; } - *pNext += HTTP_HEADER_LINE_SEPARATOR_LEN; + *pNext += 2U; } /* Mock helper that parses the response body starting from pNext. */ @@ -633,11 +633,11 @@ static llhttp_errno_t llhttp_execute_partial_header_value( llhttp_t * pParser, /* Get the first header field. */ pHeaderFieldStart = pNext; - pNext = strstr( pNext, HTTP_HEADER_FIELD_SEPARATOR ); + pNext = strstr( pNext, ": " ); headerFieldLen = ( size_t ) ( pNext - pHeaderFieldStart ); pSettings->on_header_field( pParser, pHeaderFieldStart, headerFieldLen ); - pNext += HTTP_HEADER_FIELD_SEPARATOR_LEN; + pNext += 2U; /* pNext now points to the start of the partial header value. */ pHeaderValueStart = pNext; @@ -649,11 +649,11 @@ static llhttp_errno_t llhttp_execute_partial_header_value( llhttp_t * pParser, /* In this second call to llhttp_execute mock, pData now starts * at the partial header value. */ pHeaderValueStart = pNext; - pNext = strstr( pNext, HTTP_HEADER_LINE_SEPARATOR ); + pNext = strstr( pNext, "\r\n" ); headerValueLen = ( size_t ) ( pNext - pHeaderValueStart ); pSettings->on_header_value( pParser, pHeaderValueStart, headerValueLen ); - pNext += HTTP_HEADER_FIELD_SEPARATOR_LEN; + pNext += 2U; helper_parse_headers( &pNext, pParser, pSettings ); helper_parse_headers_finish( &pNext, pParser, pSettings, &isHeadResponse ); @@ -730,16 +730,16 @@ static llhttp_errno_t llhttp_execute_chunked_body( llhttp_t * pParser, pChunkHeader = pNext; bodyLen = ( size_t ) strtoul( pChunkHeader, NULL, 16 ); - pNext = strstr( pNext, HTTP_HEADER_LINE_SEPARATOR ); - pNext += HTTP_HEADER_LINE_SEPARATOR_LEN; + pNext = strstr( pNext, "\r\n" ); + pNext += 2U; pBody = pNext; if( bodyLen > 0 ) { pSettings->on_body( pParser, pBody, bodyLen ); - pNext = strstr( pNext, HTTP_HEADER_LINE_SEPARATOR ); - pNext += HTTP_HEADER_LINE_SEPARATOR_LEN; + pNext = strstr( pNext, "\r\n" ); + pNext += 2U; } } @@ -814,7 +814,7 @@ void test_HTTPClient_Send_HEAD_request_parse_whole_response( void ) TEST_ASSERT_EQUAL( NULL, response.pBody ); TEST_ASSERT_EQUAL( 0U, response.bodyLen ); TEST_ASSERT_EQUAL( response.pBuffer + ( sizeof( HTTP_STATUS_LINE_OK ) - 1U ), response.pHeaders ); - TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_LENGTH - ( sizeof( HTTP_STATUS_LINE_OK ) - 1U ) - HTTP_HEADER_END_INDICATOR_LEN, + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_LENGTH - ( sizeof( HTTP_STATUS_LINE_OK ) - 1U ) - 4U, response.headersLen ); TEST_ASSERT_EQUAL( HTTP_STATUS_CODE_OK, response.statusCode ); TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_CONTENT_LENGTH, response.contentLength ); @@ -851,7 +851,7 @@ void test_HTTPClient_Send_PUT_request_parse_whole_response( void ) TEST_ASSERT_EQUAL( HTTPSuccess, returnStatus ); TEST_ASSERT_EQUAL( response.pBuffer + ( sizeof( HTTP_STATUS_LINE_OK ) - 1 ), response.pHeaders ); - TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_PUT_LENGTH - ( sizeof( HTTP_STATUS_LINE_OK ) - 1 ) - HTTP_HEADER_END_INDICATOR_LEN, + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_PUT_LENGTH - ( sizeof( HTTP_STATUS_LINE_OK ) - 1 ) - 4U, response.headersLen ); TEST_ASSERT_EQUAL( NULL, response.pBody ); TEST_ASSERT_EQUAL( 0, response.bodyLen ); @@ -888,7 +888,7 @@ void test_HTTPClient_Send_GET_request_parse_whole_response( void ) TEST_ASSERT_EQUAL( HTTPSuccess, returnStatus ); TEST_ASSERT_EQUAL( response.pBuffer + ( sizeof( HTTP_STATUS_LINE_OK ) - 1 ), response.pHeaders ); - TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_GET_HEADERS_LENGTH - HTTP_HEADER_END_INDICATOR_LEN, + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_GET_HEADERS_LENGTH - 4U, response.headersLen ); TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_GET_BODY_LENGTH, response.bodyLen ); TEST_ASSERT_EQUAL( HTTP_STATUS_CODE_OK, response.statusCode ); @@ -952,7 +952,7 @@ void test_HTTPClient_Send_parse_partial_header_field( void ) TEST_ASSERT_EQUAL( NULL, response.pBody ); TEST_ASSERT_EQUAL( 0, response.bodyLen ); TEST_ASSERT_EQUAL( response.pBuffer + ( sizeof( HTTP_STATUS_LINE_OK ) - 1U ), response.pHeaders ); - TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_LENGTH - ( sizeof( HTTP_STATUS_LINE_OK ) - 1U ) - HTTP_HEADER_END_INDICATOR_LEN, + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_LENGTH - ( sizeof( HTTP_STATUS_LINE_OK ) - 1U ) - 4U, response.headersLen ); TEST_ASSERT_EQUAL( HTTP_STATUS_CODE_OK, response.statusCode ); TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_CONTENT_LENGTH, response.contentLength ); @@ -983,7 +983,7 @@ void test_HTTPClient_Send_parse_partial_header_value( void ) TEST_ASSERT_EQUAL( NULL, response.pBody ); TEST_ASSERT_EQUAL( 0, response.bodyLen ); TEST_ASSERT_EQUAL( response.pBuffer + ( sizeof( HTTP_STATUS_LINE_OK ) - 1U ), response.pHeaders ); - TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_LENGTH - ( sizeof( HTTP_STATUS_LINE_OK ) - 1U ) - HTTP_HEADER_END_INDICATOR_LEN, + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_LENGTH - ( sizeof( HTTP_STATUS_LINE_OK ) - 1U ) - 4U, response.headersLen ); TEST_ASSERT_EQUAL( HTTP_STATUS_CODE_OK, response.statusCode ); TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_HEAD_CONTENT_LENGTH, response.contentLength ); @@ -1018,7 +1018,7 @@ void test_HTTPClient_Send_parse_partial_body( void ) 0 ); TEST_ASSERT_EQUAL( HTTPSuccess, returnStatus ); TEST_ASSERT_EQUAL( response.pBuffer + ( sizeof( HTTP_STATUS_LINE_OK ) - 1 ), response.pHeaders ); - TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_GET_HEADERS_LENGTH - HTTP_HEADER_END_INDICATOR_LEN, + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_GET_HEADERS_LENGTH - 4U, response.headersLen ); TEST_ASSERT_EQUAL( response.pHeaders + HTTP_TEST_RESPONSE_GET_HEADERS_LENGTH, response.pBody ); TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_GET_BODY_LENGTH, response.bodyLen ); @@ -1054,7 +1054,7 @@ void test_HTTPClient_Send_parse_chunked_body( void ) TEST_ASSERT_EQUAL( HTTPSuccess, returnStatus ); TEST_ASSERT_EQUAL( response.pBuffer + ( sizeof( HTTP_STATUS_LINE_OK ) - 1 ), response.pHeaders ); - TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_CHUNKED_HEADERS_LENGTH - HTTP_HEADER_END_INDICATOR_LEN, + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_CHUNKED_HEADERS_LENGTH - 4U, response.headersLen ); TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_CHUNKED_BODY_LENGTH, response.bodyLen ); TEST_ASSERT_EQUAL( HTTP_STATUS_CODE_OK, response.statusCode ); @@ -1317,7 +1317,7 @@ void test_HTTPClient_Send_less_bytes_request_headers( void ) TEST_ASSERT_EQUAL( HTTPSuccess, returnStatus ); TEST_ASSERT_EQUAL( response.pBuffer + ( sizeof( HTTP_STATUS_LINE_OK ) - 1 ), response.pHeaders ); - TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_PUT_LENGTH - ( sizeof( HTTP_STATUS_LINE_OK ) - 1 ) - HTTP_HEADER_END_INDICATOR_LEN, + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_PUT_LENGTH - ( sizeof( HTTP_STATUS_LINE_OK ) - 1 ) - 4U, response.headersLen ); TEST_ASSERT_EQUAL( NULL, response.pBody ); TEST_ASSERT_EQUAL( 0, response.bodyLen ); @@ -1359,7 +1359,7 @@ void test_HTTPClient_Send_less_bytes_request_body( void ) TEST_ASSERT_EQUAL( HTTPSuccess, returnStatus ); TEST_ASSERT_EQUAL( response.pBuffer + ( sizeof( HTTP_STATUS_LINE_OK ) - 1 ), response.pHeaders ); - TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_PUT_LENGTH - ( sizeof( HTTP_STATUS_LINE_OK ) - 1 ) - HTTP_HEADER_END_INDICATOR_LEN, + TEST_ASSERT_EQUAL( HTTP_TEST_RESPONSE_PUT_LENGTH - ( sizeof( HTTP_STATUS_LINE_OK ) - 1 ) - 4U, response.headersLen ); TEST_ASSERT_EQUAL( NULL, response.pBody ); TEST_ASSERT_EQUAL( 0, response.bodyLen ); diff --git a/test/unit-test/core_http_utest.c b/test/unit-test/core_http_utest.c index d2cc932a..3b091424 100644 --- a/test/unit-test/core_http_utest.c +++ b/test/unit-test/core_http_utest.c @@ -61,7 +61,7 @@ typedef struct _headers #define HTTP_TEST_REQUEST_LINE \ ( HTTP_METHOD_GET " " \ HTTP_TEST_REQUEST_PATH " " \ - HTTP_PROTOCOL_VERSION "\r\n" ) + "HTTP/1.1" "\r\n" ) #define HTTP_TEST_REQUEST_LINE_LEN ( sizeof( HTTP_TEST_REQUEST_LINE ) - 1 ) /* Used for format parameter in snprintf(...). */ @@ -77,20 +77,20 @@ typedef struct _headers "%s: %s\r\n\r\n" /* Length of the following template HTTP header. - * \r\n - * : \r\n - * : \r\n + * <"HTTP/1.1"> \r\n + * <"User-Agent">: \r\n + * <"Host">: \r\n * \r\n * This is used to initialize the expectedHeader string. */ -#define HTTP_TEST_PREFIX_HEADER_LEN \ - ( HTTP_METHOD_GET_LEN + SPACE_CHARACTER_LEN + \ - HTTP_TEST_REQUEST_PATH_LEN + SPACE_CHARACTER_LEN + \ - HTTP_PROTOCOL_VERSION_LEN + HTTP_HEADER_LINE_SEPARATOR_LEN + \ - HTTP_USER_AGENT_FIELD_LEN + HTTP_HEADER_FIELD_SEPARATOR_LEN + \ - HTTP_USER_AGENT_VALUE_LEN + HTTP_HEADER_LINE_SEPARATOR_LEN + \ - HTTP_HOST_FIELD_LEN + HTTP_HEADER_FIELD_SEPARATOR_LEN + \ - HTTP_TEST_HOST_VALUE_LEN + HTTP_HEADER_LINE_SEPARATOR_LEN + \ - HTTP_HEADER_LINE_SEPARATOR_LEN ) +#define HTTP_TEST_PREFIX_HEADER_LEN \ + ( HTTP_METHOD_GET_LEN + 1U + \ + HTTP_TEST_REQUEST_PATH_LEN + 1U + \ + sizeof( "HTTP/1.1" ) - 1U + 2U + \ + sizeof( "User-Agent" ) - 1U + 2U + \ + sizeof( HTTP_USER_AGENT_VALUE ) - 1U + 2U + \ + sizeof( "Host" ) - 1U + 2U + \ + HTTP_TEST_HOST_VALUE_LEN + 2U + \ + 2U ) /* Add 1 because snprintf(...) writes a null byte at the end. */ #define HTTP_TEST_INITIALIZED_HEADER_BUFFER_LEN \ @@ -117,18 +117,18 @@ typedef struct _headers #define HTTP_TEST_SINGLE_HEADER_LEN \ ( HTTP_TEST_HEADER_REQUEST_LINE_LEN + \ HTTP_TEST_HEADER_FIELD_LEN + \ - HTTP_HEADER_FIELD_SEPARATOR_LEN + \ + 2U + \ HTTP_TEST_HEADER_VALUE_LEN + \ - HTTP_HEADER_LINE_SEPARATOR_LEN + \ - HTTP_HEADER_LINE_SEPARATOR_LEN ) + 2U + \ + 2U ) /* The longest possible header used for these unit tests. */ -#define HTTP_TEST_DOUBLE_HEADER_LEN \ - ( HTTP_TEST_SINGLE_HEADER_LEN + \ - HTTP_TEST_HEADER_FIELD_LEN + \ - HTTP_HEADER_FIELD_SEPARATOR_LEN + \ - HTTP_TEST_HEADER_VALUE_LEN + \ - HTTP_HEADER_LINE_SEPARATOR_LEN ) +#define HTTP_TEST_DOUBLE_HEADER_LEN \ + ( HTTP_TEST_SINGLE_HEADER_LEN + \ + HTTP_TEST_HEADER_FIELD_LEN + \ + 2U + \ + HTTP_TEST_HEADER_VALUE_LEN + \ + 2U ) #define HTTP_TEST_DOUBLE_HEADER_BUFFER_LEN \ ( HTTP_TEST_DOUBLE_HEADER_LEN + 1 ) @@ -316,21 +316,21 @@ static void addRangeToExpectedHeaders( _headers_t * expectedHeaders, const char * expectedRange, bool terminatorExists ) { - size_t expectedRangeLen = HTTP_RANGE_REQUEST_HEADER_FIELD_LEN + - HTTP_HEADER_FIELD_SEPARATOR_LEN + - HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX_LEN + + size_t expectedRangeLen = sizeof( "Range" ) - 1U + + 2U + + sizeof( "bytes=" ) - 1U + strlen( expectedRange ) + - 2 * HTTP_HEADER_LINE_SEPARATOR_LEN; + 2 * 2U; int numBytes = snprintf( ( char * ) expectedHeaders->buffer + expectedHeaders->dataLen - - ( terminatorExists ? HTTP_HEADER_LINE_SEPARATOR_LEN : 0 ), + ( terminatorExists ? 2U : 0 ), sizeof( expectedHeaders->buffer ) - expectedHeaders->dataLen, "%s%s%s%s\r\n\r\n", - HTTP_RANGE_REQUEST_HEADER_FIELD, - HTTP_HEADER_FIELD_SEPARATOR, - HTTP_RANGE_REQUEST_HEADER_VALUE_PREFIX, + "Range", + ": ", + "bytes=", expectedRange ); /* Make sure that the Range request was printed to the buffer. */ @@ -338,7 +338,7 @@ static void addRangeToExpectedHeaders( _headers_t * expectedHeaders, TEST_ASSERT_LESS_THAN( sizeof( expectedHeaders->buffer ), ( size_t ) numBytes ); expectedHeaders->dataLen += expectedRangeLen - - ( terminatorExists ? HTTP_HEADER_LINE_SEPARATOR_LEN : 0 ); + ( terminatorExists ? 2U : 0 ); } /* ============================ UNITY FIXTURES ============================== */ @@ -445,9 +445,9 @@ void test_Http_InitializeRequestHeaders_Happy_Path() numBytes = snprintf( ( char * ) expectedHeaders.buffer, sizeof( expectedHeaders.buffer ), HTTP_TEST_HEADER_FORMAT, HTTP_METHOD_GET, HTTP_TEST_REQUEST_PATH, - HTTP_PROTOCOL_VERSION, - HTTP_USER_AGENT_FIELD, HTTP_USER_AGENT_VALUE, - HTTP_HOST_FIELD, HTTP_TEST_HOST_VALUE ); + "HTTP/1.1", + "User-Agent", HTTP_USER_AGENT_VALUE, + "Host", HTTP_TEST_HOST_VALUE ); /* Make sure that the entire pre-existing data was printed to the buffer. */ TEST_ASSERT_GREATER_THAN( 0, numBytes ); TEST_ASSERT_LESS_THAN( sizeof( expectedHeaders.buffer ), ( size_t ) numBytes ); @@ -513,14 +513,14 @@ void test_Http_InitializeRequestHeaders_ReqInfo() HTTPRequestHeaders_t requestHeaders = { 0 }; HTTPRequestInfo_t requestInfo = { 0 }; int numBytes = 0; - size_t connectionKeepAliveHeaderLen = HTTP_CONNECTION_FIELD_LEN + - HTTP_HEADER_FIELD_SEPARATOR_LEN + - HTTP_CONNECTION_KEEP_ALIVE_VALUE_LEN + - HTTP_HEADER_LINE_SEPARATOR_LEN; + size_t connectionKeepAliveHeaderLen = sizeof( "Connection" ) - 1U + + 2U + + sizeof( "keep-alive" ) - 1U + + 2U; expectedHeaders.dataLen = HTTP_TEST_PREFIX_HEADER_LEN - HTTP_TEST_REQUEST_PATH_LEN + - HTTP_EMPTY_PATH_LEN + + 1U + connectionKeepAliveHeaderLen; setupRequestInfo( &requestInfo ); @@ -530,11 +530,11 @@ void test_Http_InitializeRequestHeaders_ReqInfo() requestInfo.reqFlags = HTTP_REQUEST_KEEP_ALIVE_FLAG; numBytes = snprintf( ( char * ) expectedHeaders.buffer, sizeof( expectedHeaders.buffer ), HTTP_TEST_EXTRA_HEADER_FORMAT, - HTTP_METHOD_GET, HTTP_EMPTY_PATH, - HTTP_PROTOCOL_VERSION, - HTTP_USER_AGENT_FIELD, HTTP_USER_AGENT_VALUE, - HTTP_HOST_FIELD, HTTP_TEST_HOST_VALUE, - HTTP_CONNECTION_FIELD, HTTP_CONNECTION_KEEP_ALIVE_VALUE ); + HTTP_METHOD_GET, "/", + "HTTP/1.1", + "User-Agent", HTTP_USER_AGENT_VALUE, + "Host", HTTP_TEST_HOST_VALUE, + "Connection", "keep-alive" ); /* Make sure that the entire pre-existing data was printed to the buffer. */ TEST_ASSERT_GREATER_THAN( 0, numBytes ); TEST_ASSERT_LESS_THAN( sizeof( expectedHeaders.buffer ), ( size_t ) numBytes ); @@ -548,16 +548,16 @@ void test_Http_InitializeRequestHeaders_ReqInfo() expectedHeaders.dataLen ); /* Repeat the test above but with length of path == 0 for coverage. */ - requestInfo.pPath = HTTP_EMPTY_PATH; + requestInfo.pPath = "/"; requestInfo.pathLen = 0; requestInfo.reqFlags = HTTP_REQUEST_KEEP_ALIVE_FLAG; numBytes = snprintf( ( char * ) expectedHeaders.buffer, sizeof( expectedHeaders.buffer ), HTTP_TEST_EXTRA_HEADER_FORMAT, - HTTP_METHOD_GET, HTTP_EMPTY_PATH, - HTTP_PROTOCOL_VERSION, - HTTP_USER_AGENT_FIELD, HTTP_USER_AGENT_VALUE, - HTTP_HOST_FIELD, HTTP_TEST_HOST_VALUE, - HTTP_CONNECTION_FIELD, HTTP_CONNECTION_KEEP_ALIVE_VALUE ); + HTTP_METHOD_GET, "/", + "HTTP/1.1", + "User-Agent", HTTP_USER_AGENT_VALUE, + "Host", HTTP_TEST_HOST_VALUE, + "Connection", "keep-alive" ); /* Make sure that the entire pre-existing data was printed to the buffer. */ TEST_ASSERT_GREATER_THAN( 0, numBytes ); TEST_ASSERT_LESS_THAN( sizeof( expectedHeaders.buffer ), ( size_t ) numBytes ); @@ -1507,7 +1507,7 @@ void test_Http_ReadHeader_EmptyHeaderValue() pFieldLocToReturn = &pTestResponseEmptyValue[ headerFieldInRespLoc ]; fieldLenToReturn = headerFieldInRespLen; /* Add two characters past the empty value to point to the next field. */ - pValueLocToReturn = &pTestResponseEmptyValue[ headerValInRespLoc + HTTP_HEADER_LINE_SEPARATOR_LEN ]; + pValueLocToReturn = &pTestResponseEmptyValue[ headerValInRespLoc + 2U ]; /* llhttp will pass in a value of zero for an empty value. */ valueLenToReturn = 0U; invokeHeaderFieldCallback = 1U;