@@ -573,9 +573,8 @@ private List<GCHandle> SerializeHeaders(bool isOpaqueUpgrade)
573
573
int numKnownMultiHeaders = 0 ;
574
574
foreach ( var headerPair in Headers )
575
575
{
576
- if ( headerPair . Value . Count == 0 )
576
+ if ( headerPair . Value . Where ( s => s != null ) . Count ( ) == 0 )
577
577
{
578
- // TODO: Have the collection exclude empty headers.
579
578
continue ;
580
579
}
581
580
// See if this is an unknown header
@@ -585,9 +584,9 @@ private List<GCHandle> SerializeHeaders(bool isOpaqueUpgrade)
585
584
if ( lookup == - 1 ||
586
585
( isOpaqueUpgrade && lookup == ( int ) HttpApi . HTTP_RESPONSE_HEADER_ID . Enum . HttpHeaderConnection ) )
587
586
{
588
- numUnknownHeaders += headerPair . Value . Count ;
587
+ numUnknownHeaders += headerPair . Value . Where ( s => s != null ) . Count ( ) ;
589
588
}
590
- else if ( headerPair . Value . Count > 1 )
589
+ else if ( headerPair . Value . Where ( s => ! string . IsNullOrEmpty ( s ) ) . Count ( ) > 1 )
591
590
{
592
591
numKnownMultiHeaders ++ ;
593
592
}
@@ -600,9 +599,8 @@ private List<GCHandle> SerializeHeaders(bool isOpaqueUpgrade)
600
599
{
601
600
foreach ( var headerPair in Headers )
602
601
{
603
- if ( headerPair . Value . Count == 0 )
602
+ if ( headerPair . Value . Where ( s => s != null ) . Count ( ) == 0 )
604
603
{
605
- // TODO: Have the collection exclude empty headers.
606
604
continue ;
607
605
}
608
606
headerName = headerPair . Key ;
@@ -623,6 +621,13 @@ private List<GCHandle> SerializeHeaders(bool isOpaqueUpgrade)
623
621
624
622
for ( int headerValueIndex = 0 ; headerValueIndex < headerValues . Count ; headerValueIndex ++ )
625
623
{
624
+ headerValue = headerValues [ headerValueIndex ] ;
625
+
626
+ if ( headerValue == null )
627
+ {
628
+ continue ;
629
+ }
630
+
626
631
// Add Name
627
632
bytes = new byte [ HeaderEncoding . GetByteCount ( headerName ) ] ;
628
633
unknownHeaders [ _nativeResponse . Response_V1 . Headers . UnknownHeaderCount ] . NameLength = ( ushort ) bytes . Length ;
@@ -632,7 +637,6 @@ private List<GCHandle> SerializeHeaders(bool isOpaqueUpgrade)
632
637
unknownHeaders [ _nativeResponse . Response_V1 . Headers . UnknownHeaderCount ] . pName = ( sbyte * ) gcHandle . AddrOfPinnedObject ( ) ;
633
638
634
639
// Add Value
635
- headerValue = headerValues [ headerValueIndex ] ;
636
640
bytes = new byte [ HeaderEncoding . GetByteCount ( headerValue ) ] ;
637
641
unknownHeaders [ _nativeResponse . Response_V1 . Headers . UnknownHeaderCount ] . RawValueLength = ( ushort ) bytes . Length ;
638
642
HeaderEncoding . GetBytes ( headerValue , 0 , bytes . Length , bytes , 0 ) ;
@@ -642,20 +646,17 @@ private List<GCHandle> SerializeHeaders(bool isOpaqueUpgrade)
642
646
_nativeResponse . Response_V1 . Headers . UnknownHeaderCount ++ ;
643
647
}
644
648
}
645
- else if ( headerPair . Value . Count == 1 )
649
+ else if ( headerPair . Value . Where ( s => ! string . IsNullOrEmpty ( s ) ) . Count ( ) == 1 )
646
650
{
647
651
headerValue = headerValues [ 0 ] ;
648
- if ( headerValue != null )
649
- {
650
- bytes = new byte [ HeaderEncoding . GetByteCount ( headerValue ) ] ;
651
- pKnownHeaders [ lookup ] . RawValueLength = ( ushort ) bytes . Length ;
652
- HeaderEncoding . GetBytes ( headerValue , 0 , bytes . Length , bytes , 0 ) ;
653
- gcHandle = GCHandle . Alloc ( bytes , GCHandleType . Pinned ) ;
654
- pinnedHeaders . Add ( gcHandle ) ;
655
- pKnownHeaders [ lookup ] . pRawValue = ( sbyte * ) gcHandle . AddrOfPinnedObject ( ) ;
656
- }
652
+ bytes = new byte [ HeaderEncoding . GetByteCount ( headerValue ) ] ;
653
+ pKnownHeaders [ lookup ] . RawValueLength = ( ushort ) bytes . Length ;
654
+ HeaderEncoding . GetBytes ( headerValue , 0 , bytes . Length , bytes , 0 ) ;
655
+ gcHandle = GCHandle . Alloc ( bytes , GCHandleType . Pinned ) ;
656
+ pinnedHeaders . Add ( gcHandle ) ;
657
+ pKnownHeaders [ lookup ] . pRawValue = ( sbyte * ) gcHandle . AddrOfPinnedObject ( ) ;
657
658
}
658
- else
659
+ else if ( headerPair . Value . Where ( s => ! string . IsNullOrEmpty ( s ) ) . Count ( ) > 1 )
659
660
{
660
661
if ( knownHeaderInfo == null )
661
662
{
@@ -673,15 +674,21 @@ private List<GCHandle> SerializeHeaders(bool isOpaqueUpgrade)
673
674
header . HeaderId = ( HttpApi . HTTP_RESPONSE_HEADER_ID . Enum ) lookup ;
674
675
header . Flags = HttpApi . HTTP_RESPONSE_INFO_FLAGS . PreserveOrder ; // TODO: The docs say this is for www-auth only.
675
676
676
- HttpApi . HTTP_KNOWN_HEADER [ ] nativeHeaderValues = new HttpApi . HTTP_KNOWN_HEADER [ headerValues . Count ] ;
677
+ HttpApi . HTTP_KNOWN_HEADER [ ] nativeHeaderValues = new HttpApi . HTTP_KNOWN_HEADER [ headerValues . Where ( s => ! string . IsNullOrEmpty ( s ) ) . Count ( ) ] ;
677
678
gcHandle = GCHandle . Alloc ( nativeHeaderValues , GCHandleType . Pinned ) ;
678
679
pinnedHeaders . Add ( gcHandle ) ;
679
680
header . KnownHeaders = ( HttpApi . HTTP_KNOWN_HEADER * ) gcHandle . AddrOfPinnedObject ( ) ;
680
681
681
682
for ( int headerValueIndex = 0 ; headerValueIndex < headerValues . Count ; headerValueIndex ++ )
682
683
{
683
- // Add Value
684
684
headerValue = headerValues [ headerValueIndex ] ;
685
+
686
+ if ( string . IsNullOrEmpty ( headerValue ) )
687
+ {
688
+ continue ;
689
+ }
690
+
691
+ // Add Valuegit
685
692
bytes = new byte [ HeaderEncoding . GetByteCount ( headerValue ) ] ;
686
693
nativeHeaderValues [ header . KnownHeaderCount ] . RawValueLength = ( ushort ) bytes . Length ;
687
694
HeaderEncoding . GetBytes ( headerValue , 0 , bytes . Length , bytes , 0 ) ;
0 commit comments