@@ -143,6 +143,38 @@ public async Task Match_HostWithPort_InferHttpsPort()
143143 MatcherAssert . AssertMatch ( context , httpContext , endpoint ) ;
144144 }
145145
146+ [ Fact ]
147+ public async Task Match_HostWithPort_NoHostHeader ( )
148+ {
149+ // Arrange
150+ var endpoint = CreateEndpoint ( "/hello" , hosts : new string [ ] { "contoso.com:443" , } ) ;
151+
152+ var matcher = CreateMatcher ( endpoint ) ;
153+ var ( httpContext , context ) = CreateContext ( "/hello" , null , "https" ) ;
154+
155+ // Act
156+ await matcher . MatchAsync ( httpContext , context ) ;
157+
158+ // Assert
159+ MatcherAssert . AssertNotMatch ( context , httpContext ) ;
160+ }
161+
162+ [ Fact ]
163+ public async Task Match_Port_NoHostHeader_InferHttpsPort ( )
164+ {
165+ // Arrange
166+ var endpoint = CreateEndpoint ( "/hello" , hosts : new string [ ] { "*:443" , } ) ;
167+
168+ var matcher = CreateMatcher ( endpoint ) ;
169+ var ( httpContext , context ) = CreateContext ( "/hello" , null , "https" ) ;
170+
171+ // Act
172+ await matcher . MatchAsync ( httpContext , context ) ;
173+
174+ // Assert
175+ MatcherAssert . AssertMatch ( context , httpContext , endpoint ) ;
176+ }
177+
146178 [ Fact ]
147179 public async Task Match_NoMetadata_MatchesAnyHost ( )
148180 {
@@ -230,7 +262,10 @@ internal static (HttpContext httpContext, EndpointSelectorContext context) Creat
230262 string scheme = null )
231263 {
232264 var httpContext = new DefaultHttpContext ( ) ;
233- httpContext . Request . Host = new HostString ( host ) ;
265+ if ( host != null )
266+ {
267+ httpContext . Request . Host = new HostString ( host ) ;
268+ }
234269 httpContext . Request . Path = path ;
235270 httpContext . Request . Scheme = scheme ;
236271
0 commit comments