/// <inheritdoc /> public Task ApplyAsync(HttpContext httpContext, CandidateSet candidates) { if (httpContext == null) { throw new ArgumentNullException(nameof(httpContext)); } if (candidates == null) { throw new ArgumentNullException(nameof(candidates)); } if (IsRequestedApiVersionAmbiguous(httpContext, out var apiVersion)) { return(CompletedTask); } if (apiVersion == null && Options.AssumeDefaultVersionWhenUnspecified) { apiVersion = TrySelectApiVersion(httpContext, candidates); httpContext.ApiVersioningFeature().RequestedApiVersion = apiVersion; } var(matched, hasCandidates) = MatchApiVersion(candidates, apiVersion); if (!matched && hasCandidates && !DifferByRouteConstraintsOnly(candidates)) { httpContext.SetEndpoint(ClientError(httpContext, candidates)); } return(CompletedTask); }
/// <summary> /// Gets the current API version requested. /// </summary> /// <param name="context">The current <see cref="HttpContext">HTTP context</see> to get the API version for.</param> /// <returns>The requested <see cref="ApiVersion">API version</see> or <c>null</c>.</returns> /// <remarks>This method will return <c>null</c> no service API version was requested or the requested /// service API version is in an invalid format.</remarks> /// <exception cref="AmbiguousApiVersionException">Multiple, different API versions were requested.</exception> public static ApiVersion?GetRequestedApiVersion(this HttpContext context) => context.ApiVersioningFeature().RequestedApiVersion;