@@ -363,6 +363,93 @@ AWS_TEST_CASE(
363
363
test_streaming_decoder_incoming_application_one_int32_header_pair_valid ,
364
364
s_test_streaming_decoder_incoming_application_one_int32_header_pair_valid_fn )
365
365
366
+ static int s_test_streaming_decoder_incoming_application_variable_headers_with_empty_length_pair_valid_fn (
367
+ struct aws_allocator * allocator ,
368
+ void * ctx ) {
369
+ (void )ctx ;
370
+ /* clang-format off */
371
+ uint8_t test_data [] = {
372
+ 0x00 , 0x00 , 0x00 , 0x22 , /* total length */
373
+ 0x00 , 0x00 , 0x00 , 0x12 , /* headers length */
374
+ 0x2D , 0x9A , 0xD2 , 0x45 , /* prelude crc */
375
+ 0x04 , /* header name length */
376
+ 'b' , 'u' , 'f' , 'f' , /* header name */
377
+ 0x06 , /* header value type (BYTE ARRAY)*/
378
+ 0x00 , 0x00 , /* header value length */
379
+ 0x06 , /* header name length */
380
+ 's' , 't' , 'r' , 'i' ,'n' ,'g' , /* header name */
381
+ 0x07 , /* header value type (String)*/
382
+ 0x00 , 0x00 , /* header value length */
383
+ 0xC8 , 0x4C , 0xF8 , 0x53 /* message crc */
384
+ };
385
+ /* clang-format on */
386
+ struct test_decoder_data decoder_data = {
387
+ .latest_payload = 0 ,
388
+ .written = 0 ,
389
+ .alloc = allocator ,
390
+ .latest_error = 0 ,
391
+ };
392
+ aws_event_stream_headers_list_init (& decoder_data .headers_list , allocator );
393
+ struct aws_event_stream_streaming_decoder_options decoder_options = {
394
+ .on_payload_segment = s_decoder_test_on_payload_segment ,
395
+ .on_prelude = s_decoder_test_on_prelude_received ,
396
+ .on_header = s_decoder_test_header_received ,
397
+ .on_complete = s_decoder_test_on_complete ,
398
+ .on_error = s_decoder_test_on_error ,
399
+ .user_data = & decoder_data };
400
+
401
+ struct aws_event_stream_streaming_decoder decoder ;
402
+ aws_event_stream_streaming_decoder_init_from_options (& decoder , allocator , & decoder_options );
403
+
404
+ struct aws_byte_buf test_buf = aws_byte_buf_from_array (test_data , sizeof (test_data ));
405
+ ASSERT_SUCCESS (
406
+ aws_event_stream_streaming_decoder_pump (& decoder , & test_buf ), "Message validation should have succeeded" );
407
+ ASSERT_SUCCESS (decoder_data .latest_error , "No Error callback shouldn't have been called" );
408
+
409
+ ASSERT_INT_EQUALS (0x00000022 , decoder_data .latest_prelude .total_len );
410
+ ASSERT_INT_EQUALS (0x00000012 , decoder_data .latest_prelude .headers_len );
411
+ ASSERT_INT_EQUALS (0x2D9AD245 , decoder_data .latest_prelude .prelude_crc );
412
+ ASSERT_UINT_EQUALS (0xC84CF853 , decoder_data .message_crc );
413
+
414
+ const char * expected_header_name = "buff" ;
415
+ struct aws_event_stream_header_value_pair latest_header ;
416
+ aws_array_list_get_at (& decoder_data .headers_list , & latest_header , 0 );
417
+
418
+ ASSERT_BIN_ARRAYS_EQUALS (
419
+ expected_header_name ,
420
+ strlen (expected_header_name ),
421
+ latest_header .header_name ,
422
+ latest_header .header_name_len ,
423
+ "header name should have been %s" ,
424
+ expected_header_name );
425
+
426
+ struct aws_byte_buf latest_header_value = aws_event_stream_header_value_as_bytebuf (& latest_header );
427
+ ASSERT_INT_EQUALS (0 , latest_header_value .len );
428
+ ASSERT_NULL (latest_header_value .buffer );
429
+
430
+ const char * expected_string_header_name = "string" ;
431
+ aws_array_list_get_at (& decoder_data .headers_list , & latest_header , 1 );
432
+
433
+ ASSERT_BIN_ARRAYS_EQUALS (
434
+ expected_string_header_name ,
435
+ strlen (expected_string_header_name ),
436
+ latest_header .header_name ,
437
+ latest_header .header_name_len ,
438
+ "header name should have been %s" ,
439
+ expected_header_name );
440
+
441
+ latest_header_value = aws_event_stream_header_value_as_bytebuf (& latest_header );
442
+ ASSERT_INT_EQUALS (0 , latest_header_value .len );
443
+ ASSERT_NULL (latest_header_value .buffer );
444
+
445
+ aws_event_stream_headers_list_cleanup (& decoder_data .headers_list );
446
+ return 0 ;
447
+ }
448
+
449
+ AWS_TEST_CASE (
450
+ test_streaming_decoder_incoming_application_variable_headers_with_empty_length_pair_valid ,
451
+ s_test_streaming_decoder_incoming_application_variable_headers_with_empty_length_pair_valid_fn )
452
+
366
453
static int s_test_streaming_decoder_incoming_application_one_bool_header_pair_valid_fn (
367
454
struct aws_allocator * allocator ,
368
455
void * ctx ) {
0 commit comments