@@ -575,7 +575,6 @@ private List<GCHandle> SerializeHeaders(bool isOpaqueUpgrade)
575
575
{
576
576
if ( headerPair . Value . 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,11 +599,11 @@ 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
}
606
+
608
607
headerName = headerPair . Key ;
609
608
StringValues headerValues = headerPair . Value ;
610
609
lookup = HttpApi . HTTP_RESPONSE_HEADER_ID . IndexOfKnownHeader ( headerName ) ;
@@ -623,6 +622,13 @@ private List<GCHandle> SerializeHeaders(bool isOpaqueUpgrade)
623
622
624
623
for ( int headerValueIndex = 0 ; headerValueIndex < headerValues . Count ; headerValueIndex ++ )
625
624
{
625
+ headerValue = headerValues [ headerValueIndex ] ;
626
+
627
+ if ( headerValue == null )
628
+ {
629
+ continue ;
630
+ }
631
+
626
632
// Add Name
627
633
bytes = new byte [ HeaderEncoding . GetByteCount ( headerName ) ] ;
628
634
unknownHeaders [ _nativeResponse . Response_V1 . Headers . UnknownHeaderCount ] . NameLength = ( ushort ) bytes . Length ;
@@ -632,7 +638,6 @@ private List<GCHandle> SerializeHeaders(bool isOpaqueUpgrade)
632
638
unknownHeaders [ _nativeResponse . Response_V1 . Headers . UnknownHeaderCount ] . pName = ( sbyte * ) gcHandle . AddrOfPinnedObject ( ) ;
633
639
634
640
// Add Value
635
- headerValue = headerValues [ headerValueIndex ] ;
636
641
bytes = new byte [ HeaderEncoding . GetByteCount ( headerValue ) ] ;
637
642
unknownHeaders [ _nativeResponse . Response_V1 . Headers . UnknownHeaderCount ] . RawValueLength = ( ushort ) bytes . Length ;
638
643
HeaderEncoding . GetBytes ( headerValue , 0 , bytes . Length , bytes , 0 ) ;
@@ -642,20 +647,17 @@ private List<GCHandle> SerializeHeaders(bool isOpaqueUpgrade)
642
647
_nativeResponse . Response_V1 . Headers . UnknownHeaderCount ++ ;
643
648
}
644
649
}
645
- else if ( headerPair . Value . Count == 1 )
650
+ else if ( headerPair . Value . Where ( s => ! string . IsNullOrEmpty ( s ) ) . Count ( ) == 1 )
646
651
{
647
652
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
- }
653
+ bytes = new byte [ HeaderEncoding . GetByteCount ( headerValue ) ] ;
654
+ pKnownHeaders [ lookup ] . RawValueLength = ( ushort ) bytes . Length ;
655
+ HeaderEncoding . GetBytes ( headerValue , 0 , bytes . Length , bytes , 0 ) ;
656
+ gcHandle = GCHandle . Alloc ( bytes , GCHandleType . Pinned ) ;
657
+ pinnedHeaders . Add ( gcHandle ) ;
658
+ pKnownHeaders [ lookup ] . pRawValue = ( sbyte * ) gcHandle . AddrOfPinnedObject ( ) ;
657
659
}
658
- else
660
+ else if ( headerPair . Value . Where ( s => ! string . IsNullOrEmpty ( s ) ) . Count ( ) > 1 )
659
661
{
660
662
if ( knownHeaderInfo == null )
661
663
{
@@ -673,15 +675,21 @@ private List<GCHandle> SerializeHeaders(bool isOpaqueUpgrade)
673
675
header . HeaderId = ( HttpApi . HTTP_RESPONSE_HEADER_ID . Enum ) lookup ;
674
676
header . Flags = HttpApi . HTTP_RESPONSE_INFO_FLAGS . PreserveOrder ; // TODO: The docs say this is for www-auth only.
675
677
676
- HttpApi . HTTP_KNOWN_HEADER [ ] nativeHeaderValues = new HttpApi . HTTP_KNOWN_HEADER [ headerValues . Count ] ;
678
+ HttpApi . HTTP_KNOWN_HEADER [ ] nativeHeaderValues = new HttpApi . HTTP_KNOWN_HEADER [ headerValues . Where ( s => s != null ) . Count ( ) ] ;
677
679
gcHandle = GCHandle . Alloc ( nativeHeaderValues , GCHandleType . Pinned ) ;
678
680
pinnedHeaders . Add ( gcHandle ) ;
679
681
header . KnownHeaders = ( HttpApi . HTTP_KNOWN_HEADER * ) gcHandle . AddrOfPinnedObject ( ) ;
680
682
681
683
for ( int headerValueIndex = 0 ; headerValueIndex < headerValues . Count ; headerValueIndex ++ )
682
684
{
683
- // Add Value
684
685
headerValue = headerValues [ headerValueIndex ] ;
686
+
687
+ if ( string . IsNullOrEmpty ( headerValue ) )
688
+ {
689
+ continue ;
690
+ }
691
+
692
+ // Add Valuegit
685
693
bytes = new byte [ HeaderEncoding . GetByteCount ( headerValue ) ] ;
686
694
nativeHeaderValues [ header . KnownHeaderCount ] . RawValueLength = ( ushort ) bytes . Length ;
687
695
HeaderEncoding . GetBytes ( headerValue , 0 , bytes . Length , bytes , 0 ) ;
0 commit comments