Skip to content

Commit

Permalink
Rename DownstreamVersionPolicy to DownstreamHttpVersionPolicy
Browse files Browse the repository at this point in the history
  • Loading branch information
raman-m committed Apr 19, 2024
1 parent 201f296 commit 1585061
Show file tree
Hide file tree
Showing 19 changed files with 39 additions and 40 deletions.
8 changes: 4 additions & 4 deletions src/Ocelot/Configuration/Builder/DownstreamRouteBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class DownstreamRouteBuilder
private SecurityOptions _securityOptions;
private string _downstreamHttpMethod;
private Version _downstreamHttpVersion;
private HttpVersionPolicy _downstreamVersionPolicy;
private HttpVersionPolicy _downstreamHttpVersionPolicy;
private Dictionary<string, UpstreamHeaderTemplate> _upstreamHeaders;

public DownstreamRouteBuilder()
Expand Down Expand Up @@ -269,9 +269,9 @@ public DownstreamRouteBuilder WithUpstreamHeaders(Dictionary<string, UpstreamHea
return this;
}

public DownstreamRouteBuilder WithDownstreamPolicyVersion(HttpVersionPolicy downstreamVersionPolicy)
public DownstreamRouteBuilder WithDownstreamHttpVersionPolicy(HttpVersionPolicy downstreamHttpVersionPolicy)
{
_downstreamVersionPolicy = downstreamVersionPolicy;
_downstreamHttpVersionPolicy = downstreamHttpVersionPolicy;
return this;
}

Expand Down Expand Up @@ -312,7 +312,7 @@ public DownstreamRoute Build()
_securityOptions,
_downstreamHttpMethod,
_downstreamHttpVersion,
_downstreamVersionPolicy,
_downstreamHttpVersionPolicy,
_upstreamHeaders);
}
}
3 changes: 1 addition & 2 deletions src/Ocelot/Configuration/Builder/RouteBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,8 +76,7 @@ public Route Build()
_upstreamTemplatePattern,
_upstreamHost,
_aggregator,
_upstreamHeaders
);
_upstreamHeaders);
}
}
}
2 changes: 1 addition & 1 deletion src/Ocelot/Configuration/Creator/ConfigurationCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ public InternalConfiguration Create(FileConfiguration fileConfiguration, List<Ro

var version = _versionCreator.Create(fileConfiguration.GlobalConfiguration.DownstreamHttpVersion);

var versionPolicy = _versionPolicyCreator.Create(fileConfiguration.GlobalConfiguration.DownstreamVersionPolicy);
var versionPolicy = _versionPolicyCreator.Create(fileConfiguration.GlobalConfiguration.DownstreamHttpVersionPolicy);

return new InternalConfiguration(routes,
adminPath,
Expand Down
4 changes: 2 additions & 2 deletions src/Ocelot/Configuration/Creator/DynamicsCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -29,14 +29,14 @@ private Route SetUpDynamicRoute(FileDynamicRoute fileDynamicRoute, FileGlobalCon
.Create(fileDynamicRoute.RateLimitRule, globalConfiguration);

var version = _versionCreator.Create(fileDynamicRoute.DownstreamHttpVersion);
var versionPolicy = _versionPolicyCreator.Create(fileDynamicRoute.DownstreamVersionPolicy);
var versionPolicy = _versionPolicyCreator.Create(fileDynamicRoute.DownstreamHttpVersionPolicy);

var downstreamRoute = new DownstreamRouteBuilder()
.WithEnableRateLimiting(rateLimitOption.EnableRateLimiting)
.WithRateLimitOptions(rateLimitOption)
.WithServiceName(fileDynamicRoute.ServiceName)
.WithDownstreamHttpVersion(version)
.WithDownstreamPolicyVersion(versionPolicy)
.WithDownstreamHttpVersionPolicy(versionPolicy)
.Build();

var route = new RouteBuilder()
Expand Down
4 changes: 2 additions & 2 deletions src/Ocelot/Configuration/Creator/HttpVersionPolicyCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@ public class HttpVersionPolicyCreator : IVersionPolicyCreator
/// <summary>
/// Creates a <see cref="HttpVersionPolicy"/> by a string.
/// </summary>
/// <param name="downstreamVersionPolicy">The string representation of the version policy.</param>
/// <param name="downstreamHttpVersionPolicy">The string representation of the version policy.</param>
/// <returns>An <see cref="HttpVersionPolicy"/> enumeration value.</returns>
public HttpVersionPolicy Create(string downstreamVersionPolicy) => downstreamVersionPolicy switch
public HttpVersionPolicy Create(string downstreamHttpVersionPolicy) => downstreamHttpVersionPolicy switch
{
VersionPolicies.RequestVersionExact => HttpVersionPolicy.RequestVersionExact,
VersionPolicies.RequestVersionOrHigher => HttpVersionPolicy.RequestVersionOrHigher,
Expand Down
4 changes: 2 additions & 2 deletions src/Ocelot/Configuration/Creator/IVersionPolicyCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public interface IVersionPolicyCreator
/// <summary>
/// Creates a <see cref="HttpVersionPolicy"/> by a string.
/// </summary>
/// <param name="downstreamVersionPolicy">The string representation of the version policy.</param>
/// <param name="downstreamHttpVersionPolicy">The string representation of the version policy.</param>
/// <returns>An <see cref="HttpVersionPolicy"/> enumeration value.</returns>
HttpVersionPolicy Create(string downstreamVersionPolicy);
HttpVersionPolicy Create(string downstreamHttpVersionPolicy);
}
4 changes: 2 additions & 2 deletions src/Ocelot/Configuration/Creator/RoutesCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -112,7 +112,7 @@ private DownstreamRoute SetUpDownstreamRoute(FileRoute fileRoute, FileGlobalConf

var downstreamHttpVersion = _versionCreator.Create(fileRoute.DownstreamHttpVersion);

var downstreamVersionPolicy = _versionPolicyCreator.Create(fileRoute.DownstreamVersionPolicy);
var downstreamHttpVersionPolicy = _versionPolicyCreator.Create(fileRoute.DownstreamHttpVersionPolicy);

var route = new DownstreamRouteBuilder()
.WithKey(fileRoute.Key)
Expand Down Expand Up @@ -149,7 +149,7 @@ private DownstreamRoute SetUpDownstreamRoute(FileRoute fileRoute, FileGlobalConf
.WithDangerousAcceptAnyServerCertificateValidator(fileRoute.DangerousAcceptAnyServerCertificateValidator)
.WithSecurityOptions(securityOptions)
.WithDownstreamHttpVersion(downstreamHttpVersion)
.WithDownstreamPolicyVersion(downstreamVersionPolicy)
.WithDownstreamHttpVersionPolicy(downstreamHttpVersionPolicy)
.WithDownStreamHttpMethod(fileRoute.DownstreamHttpMethod)
.Build();

Expand Down
6 changes: 3 additions & 3 deletions src/Ocelot/Configuration/DownstreamRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public DownstreamRoute(
SecurityOptions securityOptions,
string downstreamHttpMethod,
Version downstreamHttpVersion,
HttpVersionPolicy downstreamVersionPolicy,
HttpVersionPolicy downstreamHttpVersionPolicy,
Dictionary<string, UpstreamHeaderTemplate> upstreamHeaders)
{
DangerousAcceptAnyServerCertificateValidator = dangerousAcceptAnyServerCertificateValidator;
Expand Down Expand Up @@ -77,7 +77,7 @@ public DownstreamRoute(
SecurityOptions = securityOptions;
DownstreamHttpMethod = downstreamHttpMethod;
DownstreamHttpVersion = downstreamHttpVersion;
DownstreamVersionPolicy = downstreamVersionPolicy;
DownstreamHttpVersionPolicy = downstreamHttpVersionPolicy;
UpstreamHeaders = upstreamHeaders ?? new();
}

Expand Down Expand Up @@ -125,7 +125,7 @@ public DownstreamRoute(
/// <item><see href="https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httprequestmessage.versionpolicy">HttpRequestMessage.VersionPolicy Property</see></item>
/// </list>
/// </remarks>
public HttpVersionPolicy DownstreamVersionPolicy { get; }
public HttpVersionPolicy DownstreamHttpVersionPolicy { get; }
public Dictionary<string, UpstreamHeaderTemplate> UpstreamHeaders { get; }
}
}
2 changes: 1 addition & 1 deletion src/Ocelot/Configuration/File/FileDynamicRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,6 @@ public class FileDynamicRoute
/// <item><see href="https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httprequestmessage.versionpolicy">HttpRequestMessage.VersionPolicy Property</see></item>
/// </list>
/// </remarks>
public string DownstreamVersionPolicy { get; set; }
public string DownstreamHttpVersionPolicy { get; set; }
}
}
2 changes: 1 addition & 1 deletion src/Ocelot/Configuration/File/FileGlobalConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,6 @@ public FileGlobalConfiguration()
/// <item><see href="https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httprequestmessage.versionpolicy">HttpRequestMessage.VersionPolicy Property</see></item>
/// </list>
/// </remarks>
public string DownstreamVersionPolicy { get; set; }
public string DownstreamHttpVersionPolicy { get; set; }
}
}
4 changes: 2 additions & 2 deletions src/Ocelot/Configuration/File/FileRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public FileRoute(FileRoute from)
/// <item><see href="https://learn.microsoft.com/en-us/dotnet/api/system.net.http.httprequestmessage.versionpolicy">HttpRequestMessage.VersionPolicy Property</see></item>
/// </list>
/// </remarks>
public string DownstreamVersionPolicy { get; set; }
public string DownstreamHttpVersionPolicy { get; set; }

public FileCacheOptions FileCacheOptions { get; set; }
public FileHttpHandlerOptions HttpHandlerOptions { get; set; }
Expand Down Expand Up @@ -103,7 +103,7 @@ public static void DeepCopy(FileRoute from, FileRoute to)
to.DownstreamHttpVersion = from.DownstreamHttpVersion;
to.DownstreamPathTemplate = from.DownstreamPathTemplate;
to.DownstreamScheme = from.DownstreamScheme;
to.DownstreamVersionPolicy = from.DownstreamVersionPolicy;
to.DownstreamHttpVersionPolicy = from.DownstreamHttpVersionPolicy;
to.FileCacheOptions = new(from.FileCacheOptions);
to.HttpHandlerOptions = new(from.HttpHandlerOptions);
to.Key = from.Key;
Expand Down
4 changes: 2 additions & 2 deletions src/Ocelot/Configuration/IInternalConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public interface IInternalConfiguration

Version DownstreamHttpVersion { get; }

/// <summary>Global HTTP version policy. It is related to <see cref="FileRoute.DownstreamVersionPolicy"/> property.</summary>
/// <summary>Global HTTP version policy. It is related to <see cref="FileRoute.DownstreamHttpVersionPolicy"/> property.</summary>
/// <value>An <see cref="HttpVersionPolicy"/> enumeration value.</value>
HttpVersionPolicy? DownstreamVersionPolicy { get; }
HttpVersionPolicy? DownstreamHttpVersionPolicy { get; }
}
}
8 changes: 4 additions & 4 deletions src/Ocelot/Configuration/InternalConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ public InternalConfiguration(
QoSOptions qoSOptions,
HttpHandlerOptions httpHandlerOptions,
Version downstreamHttpVersion,
HttpVersionPolicy? downstreamVersionPolicy)
HttpVersionPolicy? downstreamHttpVersionPolicy)
{
Routes = routes;
AdministrationPath = administrationPath;
Expand All @@ -25,7 +25,7 @@ public InternalConfiguration(
QoSOptions = qoSOptions;
HttpHandlerOptions = httpHandlerOptions;
DownstreamHttpVersion = downstreamHttpVersion;
DownstreamVersionPolicy = downstreamVersionPolicy;
DownstreamHttpVersionPolicy = downstreamHttpVersionPolicy;
}

public List<Route> Routes { get; }
Expand All @@ -39,8 +39,8 @@ public InternalConfiguration(

public Version DownstreamHttpVersion { get; }

/// <summary>Global HTTP version policy. It is related to <see cref="FileRoute.DownstreamVersionPolicy"/> property.</summary>
/// <summary>Global HTTP version policy. It is related to <see cref="FileRoute.DownstreamHttpVersionPolicy"/> property.</summary>
/// <value>An <see cref="HttpVersionPolicy"/> enumeration value.</value>
public HttpVersionPolicy? DownstreamVersionPolicy { get; }
public HttpVersionPolicy? DownstreamHttpVersionPolicy { get; }
}
}
4 changes: 2 additions & 2 deletions src/Ocelot/Configuration/Validator/RouteFluentValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -86,9 +86,9 @@ public RouteFluentValidator(IAuthenticationSchemeProvider authenticationSchemePr
RuleFor(r => r.DownstreamHttpVersion).Matches("^[0-9]([.,][0-9]{1,1})?$");
});

When(route => !string.IsNullOrEmpty(route.DownstreamVersionPolicy), () =>
When(route => !string.IsNullOrEmpty(route.DownstreamHttpVersionPolicy), () =>
{
RuleFor(r => r.DownstreamVersionPolicy).Matches($@"^({VersionPolicies.RequestVersionExact}|{VersionPolicies.RequestVersionOrHigher}|{VersionPolicies.RequestVersionOrLower})$");
RuleFor(r => r.DownstreamHttpVersionPolicy).Matches($@"^({VersionPolicies.RequestVersionExact}|{VersionPolicies.RequestVersionOrHigher}|{VersionPolicies.RequestVersionOrLower})$");
});
}

Expand Down
2 changes: 1 addition & 1 deletion src/Ocelot/Request/Mapper/RequestMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public HttpRequestMessage Map(HttpRequest request, DownstreamRoute downstreamRou
Method = MapMethod(request, downstreamRoute),
RequestUri = MapUri(request),
Version = downstreamRoute.DownstreamHttpVersion,
VersionPolicy = downstreamRoute.DownstreamVersionPolicy,
VersionPolicy = downstreamRoute.DownstreamHttpVersionPolicy,
};

MapHeaders(request, requestMessage);
Expand Down
2 changes: 1 addition & 1 deletion test/Ocelot.AcceptanceTests/DefaultVersionPolicyTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,7 @@ private static void GivenThereIsAServiceRunningOn(int port, HttpProtocols protoc
DownstreamHostAndPorts = new() { new("localhost", port) },
DownstreamScheme = Uri.UriSchemeHttps, // !!!
DownstreamHttpVersion = httpVersion,
DownstreamVersionPolicy = versionPolicy,
DownstreamHttpVersionPolicy = versionPolicy,
DangerousAcceptAnyServerCertificateValidator = true,
};
}
12 changes: 6 additions & 6 deletions test/Ocelot.UnitTests/Configuration/DynamicsCreatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ public void should_return_re_routes()
EnableRateLimiting = false,
},
DownstreamHttpVersion = "1.1",
DownstreamVersionPolicy = VersionPolicies.RequestVersionOrLower,
DownstreamHttpVersionPolicy = VersionPolicies.RequestVersionOrLower,
},
new()
{
Expand All @@ -63,7 +63,7 @@ public void should_return_re_routes()
EnableRateLimiting = true,
},
DownstreamHttpVersion = "2.0",
DownstreamVersionPolicy = VersionPolicies.RequestVersionOrHigher,
DownstreamHttpVersionPolicy = VersionPolicies.RequestVersionOrHigher,
},
},
};
Expand Down Expand Up @@ -93,8 +93,8 @@ private void ThenTheVersionCreatorIsCalledCorrectly()
_versionCreator.Verify(x => x.Create(_fileConfig.DynamicRoutes[0].DownstreamHttpVersion), Times.Once);
_versionCreator.Verify(x => x.Create(_fileConfig.DynamicRoutes[1].DownstreamHttpVersion), Times.Once);

_versionPolicyCreator.Verify(x => x.Create(_fileConfig.DynamicRoutes[0].DownstreamVersionPolicy), Times.Once);
_versionPolicyCreator.Verify(x => x.Create(_fileConfig.DynamicRoutes[1].DownstreamVersionPolicy), Times.Once);
_versionPolicyCreator.Verify(x => x.Create(_fileConfig.DynamicRoutes[0].DownstreamHttpVersionPolicy), Times.Once);
_versionPolicyCreator.Verify(x => x.Create(_fileConfig.DynamicRoutes[1].DownstreamHttpVersionPolicy), Times.Once);
}

private void ThenTheRoutesAreReturned()
Expand All @@ -103,13 +103,13 @@ private void ThenTheRoutesAreReturned()
_result[0].DownstreamRoute[0].EnableEndpointEndpointRateLimiting.ShouldBeFalse();
_result[0].DownstreamRoute[0].RateLimitOptions.ShouldBe(_rlo1);
_result[0].DownstreamRoute[0].DownstreamHttpVersion.ShouldBe(_version);
_result[0].DownstreamRoute[0].DownstreamVersionPolicy.ShouldBe(_versionPolicy);
_result[0].DownstreamRoute[0].DownstreamHttpVersionPolicy.ShouldBe(_versionPolicy);
_result[0].DownstreamRoute[0].ServiceName.ShouldBe(_fileConfig.DynamicRoutes[0].ServiceName);

_result[1].DownstreamRoute[0].EnableEndpointEndpointRateLimiting.ShouldBeTrue();
_result[1].DownstreamRoute[0].RateLimitOptions.ShouldBe(_rlo2);
_result[1].DownstreamRoute[0].DownstreamHttpVersion.ShouldBe(_version);
_result[1].DownstreamRoute[0].DownstreamVersionPolicy.ShouldBe(_versionPolicy);
_result[1].DownstreamRoute[0].DownstreamHttpVersionPolicy.ShouldBe(_versionPolicy);
_result[1].DownstreamRoute[0].ServiceName.ShouldBe(_fileConfig.DynamicRoutes[1].ServiceName);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public List<Route> Routes
public QoSOptions QoSOptions { get; }
public HttpHandlerOptions HttpHandlerOptions { get; }
public Version DownstreamHttpVersion { get; }
public HttpVersionPolicy? DownstreamVersionPolicy { get; }
public HttpVersionPolicy? DownstreamHttpVersionPolicy { get; }
}
}
}
2 changes: 1 addition & 1 deletion test/Ocelot.UnitTests/Configuration/RoutesCreatorTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ private void WhenICreate()
private void ThenTheRouteIsSet(FileRoute expected, int routeIndex)
{
_result[routeIndex].DownstreamRoute[0].DownstreamHttpVersion.ShouldBe(_expectedVersion);
_result[routeIndex].DownstreamRoute[0].DownstreamVersionPolicy.ShouldBe(_expectedVersionPolicy);
_result[routeIndex].DownstreamRoute[0].DownstreamHttpVersionPolicy.ShouldBe(_expectedVersionPolicy);
_result[routeIndex].DownstreamRoute[0].IsAuthenticated.ShouldBe(_rro.IsAuthenticated);
_result[routeIndex].DownstreamRoute[0].IsAuthorized.ShouldBe(_rro.IsAuthorized);
_result[routeIndex].DownstreamRoute[0].IsCached.ShouldBe(_rro.IsCached);
Expand Down

0 comments on commit 1585061

Please sign in to comment.