mirror of
https://github.com/nsnail/Ocelot.git
synced 2025-06-19 22:08:17 +08:00
tests for version creator
This commit is contained in:
@ -43,7 +43,7 @@ namespace Ocelot.Configuration.Builder
|
||||
private bool _dangerousAcceptAnyServerCertificateValidator;
|
||||
private SecurityOptions _securityOptions;
|
||||
private string _downstreamHttpMethod;
|
||||
private string _downstreamHttpVersion;
|
||||
private Version _downstreamHttpVersion;
|
||||
|
||||
public DownstreamReRouteBuilder()
|
||||
{
|
||||
@ -257,9 +257,9 @@ namespace Ocelot.Configuration.Builder
|
||||
return this;
|
||||
}
|
||||
|
||||
public DownstreamReRouteBuilder WithHttpVersion(string httpVersion)
|
||||
public DownstreamReRouteBuilder WithHttpVersion(Version downstreamHttpVersion)
|
||||
{
|
||||
_downstreamHttpVersion = httpVersion;
|
||||
_downstreamHttpVersion = downstreamHttpVersion;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
9
src/Ocelot/Configuration/Creator/IVersionCreator.cs
Normal file
9
src/Ocelot/Configuration/Creator/IVersionCreator.cs
Normal file
@ -0,0 +1,9 @@
|
||||
namespace Ocelot.Configuration.Creator
|
||||
{
|
||||
using System;
|
||||
|
||||
public interface IVersionCreator
|
||||
{
|
||||
Version Create(string downstreamHttpVersion);
|
||||
}
|
||||
}
|
@ -22,6 +22,7 @@ namespace Ocelot.Configuration.Creator
|
||||
private readonly IDownstreamAddressesCreator _downstreamAddressesCreator;
|
||||
private readonly IReRouteKeyCreator _reRouteKeyCreator;
|
||||
private readonly ISecurityOptionsCreator _securityOptionsCreator;
|
||||
private readonly IVersionCreator _versionCreator;
|
||||
|
||||
public ReRoutesCreator(
|
||||
IClaimsToThingCreator claimsToThingCreator,
|
||||
@ -37,7 +38,8 @@ namespace Ocelot.Configuration.Creator
|
||||
IDownstreamAddressesCreator downstreamAddressesCreator,
|
||||
ILoadBalancerOptionsCreator loadBalancerOptionsCreator,
|
||||
IReRouteKeyCreator reRouteKeyCreator,
|
||||
ISecurityOptionsCreator securityOptionsCreator
|
||||
ISecurityOptionsCreator securityOptionsCreator,
|
||||
IVersionCreator versionCreator
|
||||
)
|
||||
{
|
||||
_reRouteKeyCreator = reRouteKeyCreator;
|
||||
@ -55,6 +57,7 @@ namespace Ocelot.Configuration.Creator
|
||||
_httpHandlerOptionsCreator = httpHandlerOptionsCreator;
|
||||
_loadBalancerOptionsCreator = loadBalancerOptionsCreator;
|
||||
_securityOptionsCreator = securityOptionsCreator;
|
||||
_versionCreator = versionCreator;
|
||||
}
|
||||
|
||||
public List<ReRoute> Create(FileConfiguration fileConfiguration)
|
||||
@ -104,6 +107,8 @@ namespace Ocelot.Configuration.Creator
|
||||
|
||||
var securityOptions = _securityOptionsCreator.Create(fileReRoute.SecurityOptions);
|
||||
|
||||
var downstreamHttpVersion = _versionCreator.Create(fileReRoute.DownstreamHttpVersion);
|
||||
|
||||
var reRoute = new DownstreamReRouteBuilder()
|
||||
.WithKey(fileReRoute.Key)
|
||||
.WithDownstreamPathTemplate(fileReRoute.DownstreamPathTemplate)
|
||||
@ -138,7 +143,7 @@ namespace Ocelot.Configuration.Creator
|
||||
.WithAddHeadersToUpstream(hAndRs.AddHeadersToUpstream)
|
||||
.WithDangerousAcceptAnyServerCertificateValidator(fileReRoute.DangerousAcceptAnyServerCertificateValidator)
|
||||
.WithSecurityOptions(securityOptions)
|
||||
.WithHttpVersion(fileReRoute.DownstreamHttpVersion)
|
||||
.WithHttpVersion(downstreamHttpVersion)
|
||||
.WithDownStreamHttpMethod(fileReRoute.DownstreamHttpMethod)
|
||||
.Build();
|
||||
|
||||
|
17
src/Ocelot/Configuration/Creator/VersionCreator.cs
Normal file
17
src/Ocelot/Configuration/Creator/VersionCreator.cs
Normal file
@ -0,0 +1,17 @@
|
||||
namespace Ocelot.Configuration.Creator
|
||||
{
|
||||
using System;
|
||||
|
||||
public class VersionCreator : IVersionCreator
|
||||
{
|
||||
public Version Create(string downstreamHttpVersion)
|
||||
{
|
||||
if (!Version.TryParse(downstreamHttpVersion, out Version version))
|
||||
{
|
||||
version = new Version(1, 1);
|
||||
}
|
||||
|
||||
return version;
|
||||
}
|
||||
}
|
||||
}
|
@ -41,7 +41,7 @@ namespace Ocelot.Configuration
|
||||
bool dangerousAcceptAnyServerCertificateValidator,
|
||||
SecurityOptions securityOptions,
|
||||
string downstreamHttpMethod,
|
||||
string downstreamHttpVersion)
|
||||
Version downstreamHttpVersion)
|
||||
{
|
||||
DangerousAcceptAnyServerCertificateValidator = dangerousAcceptAnyServerCertificateValidator;
|
||||
AddHeadersToDownstream = addHeadersToDownstream;
|
||||
@ -112,6 +112,6 @@ namespace Ocelot.Configuration
|
||||
public bool DangerousAcceptAnyServerCertificateValidator { get; }
|
||||
public SecurityOptions SecurityOptions { get; }
|
||||
public string DownstreamHttpMethod { get; }
|
||||
public string DownstreamHttpVersion { get; }
|
||||
public Version DownstreamHttpVersion { get; }
|
||||
}
|
||||
}
|
||||
|
@ -136,6 +136,7 @@ namespace Ocelot.DependencyInjection
|
||||
Services.TryAddSingleton<IFrameworkDescription, FrameworkDescription>();
|
||||
Services.TryAddSingleton<IQoSFactory, QoSFactory>();
|
||||
Services.TryAddSingleton<IExceptionToErrorMapper, HttpExeptionToErrorMapper>();
|
||||
Services.TryAddSingleton<IVersionCreator, VersionCreator>();
|
||||
|
||||
//add security
|
||||
this.AddSecurity();
|
||||
|
@ -20,17 +20,12 @@
|
||||
{
|
||||
try
|
||||
{
|
||||
if (!Version.TryParse(downstreamReRoute.DownstreamHttpVersion, out Version version))
|
||||
{
|
||||
version = new Version(1, 1);
|
||||
}
|
||||
|
||||
var requestMessage = new HttpRequestMessage()
|
||||
{
|
||||
Content = await MapContent(request),
|
||||
Method = MapMethod(request, downstreamReRoute),
|
||||
RequestUri = MapUri(request),
|
||||
Version = version,
|
||||
Version = downstreamReRoute.DownstreamHttpVersion,
|
||||
};
|
||||
|
||||
MapHeaders(request, requestMessage);
|
||||
|
Reference in New Issue
Block a user