public async Task Invoke(HttpContext httpContext) { var feature = new EndpointFeature(); httpContext.Features.Set <IEndpointFeature>(feature); // Back compat support for users of IRoutingFeature httpContext.Features.Set <IRoutingFeature>(feature); // There's an inherent race condition between waiting for init and accessing the matcher // this is OK because once `_matcher` is initialized, it will not be set to null again. var matcher = await InitializeAsync(); await matcher.MatchAsync(httpContext, feature); if (feature.Endpoint != null) { Log.MatchSuccess(_logger, feature); } else { Log.MatchFailure(_logger); } await _next(httpContext); }
private static void SetEndpointFeature(HttpContext httpContext, EndpointFeature feature) { // An IRouteValuesFeature might have already been set // Copy its RouteValues collection if present var currentRouteValuesFeature = httpContext.Features.Get <IRouteValuesFeature>(); feature.RouteValues = currentRouteValuesFeature?.RouteValues; httpContext.Features.Set <IRoutingFeature>(feature); httpContext.Features.Set <IRouteValuesFeature>(feature); httpContext.Features.Set <IEndpointFeature>(feature); }
private HttpContext CreateHttpContext() { var feature = new EndpointFeature(); var httpContext = new DefaultHttpContext(); httpContext.Features.Set <IEndpointFeature>(feature); httpContext.Features.Set <IRouteValuesFeature>(feature); httpContext.RequestServices = new TestServiceProvider(); return(httpContext); }
private HttpContext CreateHttpContext(object ambientValues = null) { var httpContext = new DefaultHttpContext(); var feature = new EndpointFeature { RouteValues = new RouteValueDictionary(ambientValues) }; httpContext.Features.Set <IEndpointFeature>(feature); httpContext.Features.Set <IRouteValuesFeature>(feature); return(httpContext); }
protected (HttpContext httpContext, RouteValueDictionary ambientValues) CreateCurrentRequestContext( object ambientValues = null) { var feature = new EndpointFeature { RouteValues = new RouteValueDictionary(ambientValues) }; var context = new DefaultHttpContext(); context.Features.Set <IEndpointFeature>(feature); context.Features.Set <IRouteValuesFeature>(feature); return(context, feature.RouteValues); }
public void RouteData_DataTokensIsEmpty_WithoutMetadata() { // Arrange var feature = new EndpointFeature() { Endpoint = new RouteEndpoint( TestConstants.EmptyRequestDelegate, RoutePatternFactory.Parse("/"), 0, new EndpointMetadataCollection(), "test"), }; // Act var routeData = ((IRoutingFeature)feature).RouteData; // Assert Assert.Empty(routeData.DataTokens); }
public void RouteData_CanIntializeDataTokens_WithMetadata() { // Arrange var expected = new RouteValueDictionary(new { foo = 17, bar = "hello", }); var feature = new EndpointFeature() { Endpoint = new RouteEndpoint( TestConstants.EmptyRequestDelegate, RoutePatternFactory.Parse("/"), 0, new EndpointMetadataCollection(new DataTokensMetadata(expected)), "test"), }; // Act var routeData = ((IRoutingFeature)feature).RouteData; // Assert Assert.NotSame(expected, routeData.DataTokens); Assert.Equal(expected.OrderBy(kvp => kvp.Key), routeData.DataTokens.OrderBy(kvp => kvp.Key)); }
public async Task Invoke(HttpContext httpContext) { // For back-compat EndpointRouteValuesFeature implements IEndpointFeature, IRouteValuesFeature and IRoutingFeature var feature = new EndpointFeature(); SetEndpointFeature(httpContext, feature); // There's an inherent race condition between waiting for init and accessing the matcher // this is OK because once `_matcher` is initialized, it will not be set to null again. var matcher = await InitializeAsync(); await matcher.MatchAsync(httpContext, feature); if (feature.Endpoint != null) { Log.MatchSuccess(_logger, feature); } else { Log.MatchFailure(_logger); } await _next(httpContext); }
public static void MatchSuccess(ILogger logger, EndpointFeature feature) { _matchSuccess(logger, feature.Endpoint.DisplayName, null); }