Skip to content

Commit

Permalink
Merge remote-tracking branch 'upstream/master' into feature/#1126
Browse files Browse the repository at this point in the history
  • Loading branch information
ussamoo committed Feb 22, 2020
2 parents 88034a5 + 08512ec commit ae9f05e
Show file tree
Hide file tree
Showing 40 changed files with 583 additions and 44 deletions.
10 changes: 8 additions & 2 deletions build.cake
Original file line number Diff line number Diff line change
Expand Up @@ -134,11 +134,12 @@ Task("RunUnitTests")
var coverageSummaryFile = GetSubDirectories(artifactsForUnitTestsDir).First().CombineWithFilePath(File("coverage.opencover.xml"));
Information(coverageSummaryFile);
Information(artifactsForUnitTestsDir);
// todo bring back report generator to get a friendly report
// ReportGenerator(coverageSummaryFile, artifactsForUnitTestsDir);
// https://github.com/danielpalme/ReportGenerator
if (IsRunningOnCircleCI())
if (IsRunningOnCircleCI() && IsMaster())
{
var repoToken = EnvironmentVariable(coverallsRepoToken);
if (string.IsNullOrEmpty(repoToken))
Expand Down Expand Up @@ -497,4 +498,9 @@ private string GetResource(string url)
private bool IsRunningOnCircleCI()
{
return !string.IsNullOrWhiteSpace(Environment.GetEnvironmentVariable("CIRCLECI"));
}

private bool IsMaster()
{
return Environment.GetEnvironmentVariable("CIRCLE_BRANCH").ToLower() == "master";
}
8 changes: 7 additions & 1 deletion docs/features/configuration.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Here is an example ReRoute configuration, You don't need to set all of these thi
"Get"
],
"DownstreamHttpMethod": "",
"DownstreamHttpVersion": "",
"AddHeadersToRequest": {},
"AddClaimsToRequest": {},
"RouteClaimsRequirement": {},
Expand Down Expand Up @@ -278,4 +279,9 @@ Registering a callback
{
_callbackHolder.Dispose();
}
}
}
DownstreamHttpVersion
---------------------

Ocelot allows you to choose the HTTP version it will use to make the proxy request. It can be set as "1.0", "1.1" or "2.0".
11 changes: 10 additions & 1 deletion src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
using Ocelot.Configuration.Creator;
using Ocelot.Values;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http;
Expand Down Expand Up @@ -42,6 +43,7 @@ public class DownstreamReRouteBuilder
private bool _dangerousAcceptAnyServerCertificateValidator;
private SecurityOptions _securityOptions;
private string _downstreamHttpMethod;
private Version _downstreamHttpVersion;

public DownstreamReRouteBuilder()
{
Expand Down Expand Up @@ -255,6 +257,12 @@ public DownstreamReRouteBuilder WithSecurityOptions(SecurityOptions securityOpti
return this;
}

public DownstreamReRouteBuilder WithDownstreamHttpVersion(Version downstreamHttpVersion)
{
_downstreamHttpVersion = downstreamHttpVersion;
return this;
}

public DownstreamReRoute Build()
{
return new DownstreamReRoute(
Expand Down Expand Up @@ -290,7 +298,8 @@ public DownstreamReRoute Build()
_addHeadersToUpstream,
_dangerousAcceptAnyServerCertificateValidator,
_securityOptions,
_downstreamHttpMethod);
_downstreamHttpMethod,
_downstreamHttpVersion);
}
}
}
10 changes: 8 additions & 2 deletions src/Ocelot/Configuration/Creator/ConfigurationCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,20 +13,23 @@ public class ConfigurationCreator : IConfigurationCreator
private readonly IHttpHandlerOptionsCreator _httpHandlerOptionsCreator;
private readonly IAdministrationPath _adminPath;
private readonly ILoadBalancerOptionsCreator _loadBalancerOptionsCreator;
private readonly IVersionCreator _versionCreator;

public ConfigurationCreator(
IServiceProviderConfigurationCreator serviceProviderConfigCreator,
IQoSOptionsCreator qosOptionsCreator,
IHttpHandlerOptionsCreator httpHandlerOptionsCreator,
IServiceProvider serviceProvider,
ILoadBalancerOptionsCreator loadBalancerOptionsCreator
ILoadBalancerOptionsCreator loadBalancerOptionsCreator,
IVersionCreator versionCreator
)
{
_adminPath = serviceProvider.GetService<IAdministrationPath>();
_loadBalancerOptionsCreator = loadBalancerOptionsCreator;
_serviceProviderConfigCreator = serviceProviderConfigCreator;
_qosOptionsCreator = qosOptionsCreator;
_httpHandlerOptionsCreator = httpHandlerOptionsCreator;
_versionCreator = versionCreator;
}

public InternalConfiguration Create(FileConfiguration fileConfiguration, List<ReRoute> reRoutes)
Expand All @@ -41,14 +44,17 @@ public InternalConfiguration Create(FileConfiguration fileConfiguration, List<Re

var adminPath = _adminPath != null ? _adminPath.Path : null;

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

return new InternalConfiguration(reRoutes,
adminPath,
serviceProviderConfiguration,
fileConfiguration.GlobalConfiguration.RequestIdKey,
lbOptions,
fileConfiguration.GlobalConfiguration.DownstreamScheme,
qosOptions,
httpHandlerOptions
httpHandlerOptions,
version
);
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/Ocelot/Configuration/Creator/DynamicsCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@ namespace Ocelot.Configuration.Creator
public class DynamicsCreator : IDynamicsCreator
{
private readonly IRateLimitOptionsCreator _rateLimitOptionsCreator;
private readonly IVersionCreator _versionCreator;

public DynamicsCreator(IRateLimitOptionsCreator rateLimitOptionsCreator)
public DynamicsCreator(IRateLimitOptionsCreator rateLimitOptionsCreator, IVersionCreator versionCreator)
{
_rateLimitOptionsCreator = rateLimitOptionsCreator;
_versionCreator = versionCreator;
}

public List<ReRoute> Create(FileConfiguration fileConfiguration)
Expand All @@ -26,10 +28,13 @@ private ReRoute SetUpDynamicReRoute(FileDynamicReRoute fileDynamicReRoute, FileG
var rateLimitOption = _rateLimitOptionsCreator
.Create(fileDynamicReRoute.RateLimitRule, globalConfiguration);

var version = _versionCreator.Create(fileDynamicReRoute.DownstreamHttpVersion);

var downstreamReRoute = new DownstreamReRouteBuilder()
.WithEnableRateLimiting(rateLimitOption.EnableRateLimiting)
.WithRateLimitOptions(rateLimitOption)
.WithServiceName(fileDynamicReRoute.ServiceName)
.WithDownstreamHttpVersion(version)
.Build();

var reRoute = new ReRouteBuilder()
Expand Down
17 changes: 17 additions & 0 deletions src/Ocelot/Configuration/Creator/HttpVersionCreator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
namespace Ocelot.Configuration.Creator
{
using System;

public class HttpVersionCreator : IVersionCreator
{
public Version Create(string downstreamHttpVersion)
{
if (!Version.TryParse(downstreamHttpVersion, out Version version))
{
version = new Version(1, 1);
}

return version;
}
}
}
9 changes: 9 additions & 0 deletions src/Ocelot/Configuration/Creator/IVersionCreator.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
namespace Ocelot.Configuration.Creator
{
using System;

public interface IVersionCreator
{
Version Create(string downstreamHttpVersion);
}
}
8 changes: 7 additions & 1 deletion src/Ocelot/Configuration/Creator/ReRoutesCreator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ public class ReRoutesCreator : IReRoutesCreator
private readonly IDownstreamAddressesCreator _downstreamAddressesCreator;
private readonly IReRouteKeyCreator _reRouteKeyCreator;
private readonly ISecurityOptionsCreator _securityOptionsCreator;
private readonly IVersionCreator _versionCreator;

public ReRoutesCreator(
IClaimsToThingCreator claimsToThingCreator,
Expand All @@ -37,7 +38,8 @@ public ReRoutesCreator(
IDownstreamAddressesCreator downstreamAddressesCreator,
ILoadBalancerOptionsCreator loadBalancerOptionsCreator,
IReRouteKeyCreator reRouteKeyCreator,
ISecurityOptionsCreator securityOptionsCreator
ISecurityOptionsCreator securityOptionsCreator,
IVersionCreator versionCreator
)
{
_reRouteKeyCreator = reRouteKeyCreator;
Expand All @@ -55,6 +57,7 @@ ISecurityOptionsCreator securityOptionsCreator
_httpHandlerOptionsCreator = httpHandlerOptionsCreator;
_loadBalancerOptionsCreator = loadBalancerOptionsCreator;
_securityOptionsCreator = securityOptionsCreator;
_versionCreator = versionCreator;
}

public List<ReRoute> Create(FileConfiguration fileConfiguration)
Expand Down Expand Up @@ -104,6 +107,8 @@ private DownstreamReRoute SetUpDownstreamReRoute(FileReRoute fileReRoute, FileGl

var securityOptions = _securityOptionsCreator.Create(fileReRoute.SecurityOptions);

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

var reRoute = new DownstreamReRouteBuilder()
.WithKey(fileReRoute.Key)
.WithDownstreamPathTemplate(fileReRoute.DownstreamPathTemplate)
Expand Down Expand Up @@ -138,6 +143,7 @@ private DownstreamReRoute SetUpDownstreamReRoute(FileReRoute fileReRoute, FileGl
.WithAddHeadersToUpstream(hAndRs.AddHeadersToUpstream)
.WithDangerousAcceptAnyServerCertificateValidator(fileReRoute.DangerousAcceptAnyServerCertificateValidator)
.WithSecurityOptions(securityOptions)
.WithDownstreamHttpVersion(downstreamHttpVersion)
.WithDownStreamHttpMethod(fileReRoute.DownstreamHttpMethod)
.Build();

Expand Down
6 changes: 5 additions & 1 deletion src/Ocelot/Configuration/DownstreamReRoute.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
namespace Ocelot.Configuration
{
using Creator;
using System;
using System.Collections.Generic;
using Values;

Expand Down Expand Up @@ -39,7 +40,8 @@ public DownstreamReRoute(
List<AddHeader> addHeadersToUpstream,
bool dangerousAcceptAnyServerCertificateValidator,
SecurityOptions securityOptions,
string downstreamHttpMethod)
string downstreamHttpMethod,
Version downstreamHttpVersion)
{
DangerousAcceptAnyServerCertificateValidator = dangerousAcceptAnyServerCertificateValidator;
AddHeadersToDownstream = addHeadersToDownstream;
Expand Down Expand Up @@ -74,6 +76,7 @@ public DownstreamReRoute(
AddHeadersToUpstream = addHeadersToUpstream;
SecurityOptions = securityOptions;
DownstreamHttpMethod = downstreamHttpMethod;
DownstreamHttpVersion = downstreamHttpVersion;
}

public string Key { get; }
Expand Down Expand Up @@ -109,5 +112,6 @@ public DownstreamReRoute(
public bool DangerousAcceptAnyServerCertificateValidator { get; }
public SecurityOptions SecurityOptions { get; }
public string DownstreamHttpMethod { get; }
public Version DownstreamHttpVersion { get; }
}
}
1 change: 1 addition & 0 deletions src/Ocelot/Configuration/File/FileDynamicReRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@ public class FileDynamicReRoute
{
public string ServiceName { get; set; }
public FileRateLimitRule RateLimitRule { get; set; }
public string DownstreamHttpVersion { get; set; }
}
}
2 changes: 2 additions & 0 deletions src/Ocelot/Configuration/File/FileGlobalConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,5 +26,7 @@ public FileGlobalConfiguration()
public string DownstreamScheme { get; set; }

public FileHttpHandlerOptions HttpHandlerOptions { get; set; }

public string DownstreamHttpVersion { get; set; }
}
}
1 change: 1 addition & 0 deletions src/Ocelot/Configuration/File/FileReRoute.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,5 +56,6 @@ public FileReRoute()
public int Timeout { get; set; }
public bool DangerousAcceptAnyServerCertificateValidator { get; set; }
public FileSecurityOptions SecurityOptions { get; set; }
public string DownstreamHttpVersion { get; set; }
}
}
4 changes: 4 additions & 0 deletions src/Ocelot/Configuration/IInternalConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Ocelot.Configuration
{
using System;

public interface IInternalConfiguration
{
List<ReRoute> ReRoutes { get; }
Expand All @@ -19,5 +21,7 @@ public interface IInternalConfiguration
QoSOptions QoSOptions { get; }

HttpHandlerOptions HttpHandlerOptions { get; }

Version DownstreamHttpVersion { get; }
}
}
8 changes: 7 additions & 1 deletion src/Ocelot/Configuration/InternalConfiguration.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace Ocelot.Configuration
{
using System;

public class InternalConfiguration : IInternalConfiguration
{
public InternalConfiguration(
Expand All @@ -12,7 +14,8 @@ public InternalConfiguration(
LoadBalancerOptions loadBalancerOptions,
string downstreamScheme,
QoSOptions qoSOptions,
HttpHandlerOptions httpHandlerOptions)
HttpHandlerOptions httpHandlerOptions,
Version downstreamHttpVersion)
{
ReRoutes = reRoutes;
AdministrationPath = administrationPath;
Expand All @@ -22,6 +25,7 @@ public InternalConfiguration(
DownstreamScheme = downstreamScheme;
QoSOptions = qoSOptions;
HttpHandlerOptions = httpHandlerOptions;
DownstreamHttpVersion = downstreamHttpVersion;
}

public List<ReRoute> ReRoutes { get; }
Expand All @@ -32,5 +36,7 @@ public InternalConfiguration(
public string DownstreamScheme { get; }
public QoSOptions QoSOptions { get; }
public HttpHandlerOptions HttpHandlerOptions { get; }

public Version DownstreamHttpVersion { get; }
}
}
5 changes: 5 additions & 0 deletions src/Ocelot/Configuration/Validator/ReRouteFluentValidator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,11 @@ public ReRouteFluentValidator(IAuthenticationSchemeProvider authenticationScheme
RuleForEach(reRoute => reRoute.DownstreamHostAndPorts)
.SetValidator(hostAndPortValidator);
});

When(reRoute => !string.IsNullOrEmpty(reRoute.DownstreamHttpVersion), () =>
{
RuleFor(r => r.DownstreamHttpVersion).Matches("^[0-9]([.,][0-9]{1,1})?$");
});
}

private async Task<bool> IsSupportedAuthenticationProviders(FileAuthenticationOptions authenticationOptions, CancellationToken cancellationToken)
Expand Down
1 change: 1 addition & 0 deletions src/Ocelot/DependencyInjection/OcelotBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ public OcelotBuilder(IServiceCollection services, IConfiguration configurationRo
Services.TryAddSingleton<IFrameworkDescription, FrameworkDescription>();
Services.TryAddSingleton<IQoSFactory, QoSFactory>();
Services.TryAddSingleton<IExceptionToErrorMapper, HttpExeptionToErrorMapper>();
Services.TryAddSingleton<IVersionCreator, HttpVersionCreator>();

//add security
this.AddSecurity();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
namespace Ocelot.DownstreamRouteFinder.Finder
{
using System;
using Configuration;
using Configuration.Builder;
using Configuration.Creator;
Expand Down Expand Up @@ -54,6 +55,7 @@ public Response<DownstreamRoute> Get(string upstreamUrlPath, string upstreamQuer
.WithQosOptions(qosOptions)
.WithDownstreamScheme(configuration.DownstreamScheme)
.WithLoadBalancerOptions(configuration.LoadBalancerOptions)
.WithDownstreamHttpVersion(configuration.DownstreamHttpVersion)
.WithUpstreamPathTemplate(upstreamPathTemplate);

var rateLimitOptions = configuration.ReRoutes != null
Expand Down
3 changes: 2 additions & 1 deletion src/Ocelot/Request/Mapper/RequestMapper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,8 @@ public async Task<Response<HttpRequestMessage>> Map(HttpRequest request, Downstr
{
Content = await MapContent(request),
Method = MapMethod(request, downstreamReRoute),
RequestUri = MapUri(request)
RequestUri = MapUri(request),
Version = downstreamReRoute.DownstreamHttpVersion,
};

MapHeaders(request, requestMessage);
Expand Down
Loading

0 comments on commit ae9f05e

Please sign in to comment.