Skip to content

Commit

Permalink
Use 404 vs 400 when versioning only by URL and no requested versions. F…
Browse files Browse the repository at this point in the history
…ixes #911
  • Loading branch information
commonsensesoftware committed Nov 17, 2022
1 parent 341b18f commit e3644b4
Showing 1 changed file with 11 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ namespace Asp.Versioning.Routing;
internal sealed class ApiVersionPolicyJumpTable : PolicyJumpTable
{
private readonly bool versionsByUrl;
private readonly bool versionsByUrlOnly;
private readonly bool versionsByMediaTypeOnly;
private readonly RouteDestination rejection;
private readonly IReadOnlyDictionary<ApiVersion, int> destinations;
Expand All @@ -32,6 +33,7 @@ internal sealed class ApiVersionPolicyJumpTable : PolicyJumpTable
this.parser = parser;
this.options = options;
versionsByUrl = routePatterns.Count > 0;
versionsByUrlOnly = source.VersionsByUrl( allowMultipleLocations: false );
versionsByMediaTypeOnly = source.VersionsByMediaType( allowMultipleLocations: false );
}

Expand Down Expand Up @@ -61,15 +63,18 @@ public override int GetDestination( HttpContext httpContext )
return destination;
}

// 2. short-circuit if a default version cannot be assumed
if ( !options.AssumeDefaultVersionWhenUnspecified )
// 2. IApiVersionSelector cannot be used yet because there are no candidates that an
// aggregated version model can be computed from to select the 'default' API version
if ( options.AssumeDefaultVersionWhenUnspecified )
{
return rejection.Unspecified; // 400
return rejection.AssumeDefault;
}

// 3. IApiVersionSelector cannot be used yet because there are no candidates that an
// aggregated version model can be computed from to select the 'default' API version
return rejection.AssumeDefault;
// 3. unspecified
return versionsByUrlOnly
/* 404 */ ? rejection.Exit
/* 400 */ : rejection.Unspecified;

case 1:
rawApiVersion = apiVersions[0];

Expand Down

0 comments on commit e3644b4

Please sign in to comment.