@@ -153,9 +153,12 @@ public Task BadRequestIfHostHeaderDoesNotMatchRequestTarget(string requestTarget
153
153
}
154
154
155
155
[ Theory ]
156
- [ InlineData ( "Host: www.foo.comConnection: keep-alive" ) ] // Corrupted - missing line-break
157
- [ InlineData ( "Host: www.notfoo.com" ) ] // Syntactically correct but not matching
158
- public async Task CanOptOutOfBadRequestIfHostHeaderDoesNotMatchRequestTarget ( string hostHeader )
156
+ [ InlineData ( "http://www.foo.com" , "Host: www.foo.comConnection: keep-alive" , "www.foo.com" ) ] // Corrupted - missing line-break
157
+ [ InlineData ( "http://www.foo.com/" , "Host: www.notfoo.com" , "www.foo.com" ) ] // Syntactically correct but not matching
158
+ [ InlineData ( "http://www.foo.com:80" , "Host: www.notfoo.com" , "www.foo.com" ) ] // Explicit default port in request string
159
+ [ InlineData ( "http://www.foo.com:5129" , "Host: www.foo.com" , "www.foo.com:5129" ) ] // Non-default port in request string
160
+ [ InlineData ( "http://www.foo.com:5129" , "Host: www.foo.com:5128" , "www.foo.com:5129" ) ] // Different port in host header
161
+ public async Task CanOptOutOfBadRequestIfHostHeaderDoesNotMatchRequestTarget ( string requestString , string hostHeader , string expectedHost )
159
162
{
160
163
var testMeterFactory = new TestMeterFactory ( ) ;
161
164
using var connectionDuration = new MetricCollector < double > ( testMeterFactory , "Microsoft.AspNetCore.Server.Kestrel" , "kestrel.connection.duration" ) ;
@@ -175,13 +178,13 @@ public async Task CanOptOutOfBadRequestIfHostHeaderDoesNotMatchRequestTarget(str
175
178
{
176
179
using ( var client = server . CreateConnection ( ) )
177
180
{
178
- await client . SendAll ( $ "GET http://www.foo.com/api/data HTTP/1.1\r \n { hostHeader } \r \n \r \n ") ;
181
+ await client . SendAll ( $ "GET { requestString } HTTP/1.1\r \n { hostHeader } \r \n \r \n ") ;
179
182
180
183
await client . Receive ( "HTTP/1.1 200 OK" ) ;
181
184
}
182
185
}
183
186
184
- Assert . Equal ( "www.foo.com:80" , receivedHost ) ;
187
+ Assert . Equal ( expectedHost , receivedHost ) ;
185
188
186
189
Assert . Collection ( connectionDuration . GetMeasurementSnapshot ( ) , m => MetricsAssert . NoError ( m . Tags ) ) ;
187
190
}
0 commit comments