2
2
// Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
3
3
4
4
using System . Collections . Generic ;
5
+ using System . Linq ;
5
6
using System . Net . Http ;
6
7
using System . Threading . Tasks ;
7
8
using Microsoft . AspNet . Builder ;
8
9
using Microsoft . AspNet . Hosting ;
10
+ using Microsoft . AspNet . Http ;
9
11
using Microsoft . AspNet . Testing . xunit ;
10
12
using Microsoft . Extensions . Configuration ;
11
13
using Xunit ;
@@ -44,7 +46,7 @@ public async Task LargeDownload()
44
46
await context . Response . Body . WriteAsync ( bytes , 0 , bytes . Length ) ;
45
47
}
46
48
} ) ;
47
- } ) ;
49
+ } ) ;
48
50
49
51
using ( var app = hostBuilder . Build ( ) . Start ( ) )
50
52
{
@@ -70,5 +72,53 @@ public async Task LargeDownload()
70
72
}
71
73
}
72
74
}
75
+
76
+ [ ConditionalFact ]
77
+ [ FrameworkSkipCondition ( RuntimeFrameworks . Mono , SkipReason = "Test hangs after execution on mono." ) ]
78
+ public async Task IgnoreNullHeaderValues ( )
79
+ {
80
+ var config = new ConfigurationBuilder ( )
81
+ . AddInMemoryCollection ( new Dictionary < string , string >
82
+ {
83
+ { "server.urls" , "http://localhost:8793/" }
84
+ } )
85
+ . Build ( ) ;
86
+
87
+ var hostBuilder = new WebHostBuilder ( config )
88
+ . UseServerFactory ( "Microsoft.AspNet.Server.Kestrel" )
89
+ . UseStartup ( app =>
90
+ {
91
+ app . Run ( async context =>
92
+ {
93
+ context . Response . Headers . Add ( "NullString" , ( string ) null ) ;
94
+ context . Response . Headers . Add ( "EmptyString" , "" ) ;
95
+ context . Response . Headers . Add ( "NullStringArray" , new string [ ] { null } ) ;
96
+ context . Response . Headers . Add ( "EmptyStringArray" , new string [ ] { "" } ) ;
97
+ context . Response . Headers . Add ( "MixedStringArray" , new string [ ] { null , "" } ) ;
98
+
99
+ context . Response . ContentLength = 0 ;
100
+ await context . Response . WriteAsync ( "" ) ;
101
+ } ) ;
102
+ } ) ;
103
+
104
+ using ( var app = hostBuilder . Build ( ) . Start ( ) )
105
+ {
106
+ using ( var client = new HttpClient ( ) )
107
+ {
108
+ var response = await client . GetAsync ( "http://localhost:8793/" ) ;
109
+ response . EnsureSuccessStatusCode ( ) ;
110
+
111
+ var headers = response . Headers ;
112
+ Assert . False ( headers . Contains ( "NullString" ) ) ;
113
+ Assert . True ( headers . Contains ( "EmptyString" ) ) ;
114
+ Assert . Equal ( headers . GetValues ( "EmptyString" ) . Single ( ) , "" ) ;
115
+ Assert . False ( headers . Contains ( "NullStringArray" ) ) ;
116
+ Assert . True ( headers . Contains ( "EmptyStringArray" ) ) ;
117
+ Assert . Equal ( headers . GetValues ( "EmptyStringArray" ) . Single ( ) , "" ) ;
118
+ Assert . True ( headers . Contains ( "MixedStringArray" ) ) ;
119
+ Assert . Equal ( headers . GetValues ( "MixedStringArray" ) . Single ( ) , "" ) ;
120
+ }
121
+ }
122
+ }
73
123
}
74
124
}
0 commit comments