@@ -760,6 +760,32 @@ static llhttp_errno_t llhttp_execute_partial_body( llhttp_t * pParser,
760760 return HPE_OK ;
761761}
762762
763+
764+ /* Mocked llhttp_execute callback that will be called when partial body has been
765+ * received from the network. It returns HPE_PAUSED to mimic stopping parsing
766+ * the body because user set HTTP_RESPONSE_DO_NOT_PARSE_BODY_FLAG. */
767+ static llhttp_errno_t llhttp_execute_partial_body_do_not_parse ( llhttp_t * pParser ,
768+ const char * pData ,
769+ size_t len ,
770+ int cmock_num_calls )
771+ {
772+ ( void ) cmock_num_calls ;
773+ ( void ) len ;
774+
775+ const char * pNext = pData ;
776+ llhttp_settings_t * pSettings = ( llhttp_settings_t * ) pParser -> settings ;
777+
778+ pSettings -> on_message_begin ( pParser );
779+
780+ helper_parse_status_line ( & pNext , pParser , pSettings );
781+ helper_parse_headers ( & pNext , pParser , pSettings );
782+ helper_parse_headers_finish ( & pNext , pParser , pSettings , NULL );
783+
784+ pParser -> error_pos = pNext ;
785+ pParser -> error = HPE_PAUSED ;
786+ return HPE_PAUSED ;
787+ }
788+
763789/* Mocked llhttp_execute callback that will be on a response of type
764790 * transfer-encoding chunked. */
765791static llhttp_errno_t llhttp_execute_chunked_body ( llhttp_t * pParser ,
@@ -768,6 +794,7 @@ static llhttp_errno_t llhttp_execute_chunked_body( llhttp_t * pParser,
768794 int cmock_num_calls )
769795{
770796 ( void ) cmock_num_calls ;
797+ ( void ) len ;
771798
772799 const char * pNext = pData ;
773800 uint8_t isHeadResponse = 0 ;
@@ -1158,6 +1185,47 @@ void test_HTTPClient_Send_parse_partial_body( void )
11581185
11591186/*-----------------------------------------------------------*/
11601187
1188+ /* Test successfully parsing a response where up to the middle of the body
1189+ * is received on the first network read, then the rest of the response is not
1190+ * received from the network because HTTP_RESPONSE_DO_NOT_PARSE_BODY_FLAG is set.
1191+ */
1192+ void test_HTTPClient_Send_do_not_parse_partial_body ( void )
1193+ {
1194+ HTTPStatus_t returnStatus = HTTPSuccess ;
1195+
1196+ llhttp_execute_Stub ( llhttp_execute_partial_body_do_not_parse );
1197+
1198+ memcpy ( requestHeaders .pBuffer ,
1199+ HTTP_TEST_REQUEST_GET_HEADERS ,
1200+ HTTP_TEST_REQUEST_GET_HEADERS_LENGTH );
1201+ requestHeaders .headersLen = HTTP_TEST_REQUEST_GET_HEADERS_LENGTH ;
1202+ pNetworkData = ( uint8_t * ) HTTP_TEST_RESPONSE_GET ;
1203+ networkDataLen = HTTP_TEST_RESPONSE_GET_LENGTH ;
1204+ firstPartBytes = HTTP_TEST_RESPONSE_GET_PARTIAL_BODY_LENGTH ;
1205+
1206+ response .respOptionFlags |= HTTP_RESPONSE_DO_NOT_PARSE_BODY_FLAG ;
1207+
1208+ returnStatus = HTTPClient_Send ( & transportInterface ,
1209+ & requestHeaders ,
1210+ NULL ,
1211+ 0 ,
1212+ & response ,
1213+ 0 );
1214+ TEST_ASSERT_EQUAL ( HTTPSuccess , returnStatus );
1215+ TEST_ASSERT_EQUAL ( response .pBuffer + ( sizeof ( HTTP_STATUS_LINE_OK ) - 1 ), response .pHeaders );
1216+ TEST_ASSERT_EQUAL ( HTTP_TEST_RESPONSE_GET_HEADERS_LENGTH - HTTP_HEADER_END_INDICATOR_LEN ,
1217+ response .headersLen );
1218+ TEST_ASSERT_EQUAL ( response .pHeaders + HTTP_TEST_RESPONSE_GET_HEADERS_LENGTH , response .pBody );
1219+ TEST_ASSERT_EQUAL ( HTTP_TEST_RESPONSE_GET_PARTIAL_BODY_LENGTH - HTTP_TEST_RESPONSE_HEAD_LENGTH , response .bodyLen );
1220+ TEST_ASSERT_EQUAL ( HTTP_STATUS_CODE_OK , response .statusCode );
1221+ TEST_ASSERT_EQUAL ( HTTP_TEST_RESPONSE_GET_CONTENT_LENGTH , response .contentLength );
1222+ TEST_ASSERT_EQUAL ( HTTP_TEST_RESPONSE_GET_HEADER_COUNT , response .headerCount );
1223+ TEST_ASSERT_BITS_HIGH ( HTTP_RESPONSE_CONNECTION_CLOSE_FLAG , response .respFlags );
1224+ TEST_ASSERT_BITS_LOW ( HTTP_RESPONSE_CONNECTION_KEEP_ALIVE_FLAG , response .respFlags );
1225+ }
1226+
1227+ /*-----------------------------------------------------------*/
1228+
11611229/* Test receiving a response where the body is of Transfer-Encoding chunked. */
11621230void test_HTTPClient_Send_parse_chunked_body ( void )
11631231{
0 commit comments