Skip to content

Commit def55b3

Browse files
committed
Merge branch 'andreatosato-master'
2 parents fc3b6fd + ede5650 commit def55b3

39 files changed

+575
-42
lines changed

docs/features/configuration.rst

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ Here is an example ReRoute configuration, You don't need to set all of these thi
2525
"Get"
2626
],
2727
"DownstreamHttpMethod": "",
28+
"DownstreamHttpVersion": "",
2829
"AddHeadersToRequest": {},
2930
"AddClaimsToRequest": {},
3031
"RouteClaimsRequirement": {},
@@ -278,4 +279,9 @@ Registering a callback
278279
{
279280
_callbackHolder.Dispose();
280281
}
281-
}
282+
}
283+
284+
DownstreamHttpVersion
285+
---------------------
286+
287+
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".

src/Ocelot/Configuration/Builder/DownstreamReRouteBuilder.cs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Ocelot.Configuration.Creator;
22
using Ocelot.Values;
3+
using System;
34
using System.Collections.Generic;
45
using System.Linq;
56
using System.Net.Http;
@@ -42,6 +43,7 @@ public class DownstreamReRouteBuilder
4243
private bool _dangerousAcceptAnyServerCertificateValidator;
4344
private SecurityOptions _securityOptions;
4445
private string _downstreamHttpMethod;
46+
private Version _downstreamHttpVersion;
4547

4648
public DownstreamReRouteBuilder()
4749
{
@@ -255,6 +257,12 @@ public DownstreamReRouteBuilder WithSecurityOptions(SecurityOptions securityOpti
255257
return this;
256258
}
257259

260+
public DownstreamReRouteBuilder WithDownstreamHttpVersion(Version downstreamHttpVersion)
261+
{
262+
_downstreamHttpVersion = downstreamHttpVersion;
263+
return this;
264+
}
265+
258266
public DownstreamReRoute Build()
259267
{
260268
return new DownstreamReRoute(
@@ -290,7 +298,8 @@ public DownstreamReRoute Build()
290298
_addHeadersToUpstream,
291299
_dangerousAcceptAnyServerCertificateValidator,
292300
_securityOptions,
293-
_downstreamHttpMethod);
301+
_downstreamHttpMethod,
302+
_downstreamHttpVersion);
294303
}
295304
}
296305
}

src/Ocelot/Configuration/Creator/ConfigurationCreator.cs

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,20 +13,23 @@ public class ConfigurationCreator : IConfigurationCreator
1313
private readonly IHttpHandlerOptionsCreator _httpHandlerOptionsCreator;
1414
private readonly IAdministrationPath _adminPath;
1515
private readonly ILoadBalancerOptionsCreator _loadBalancerOptionsCreator;
16+
private readonly IVersionCreator _versionCreator;
1617

1718
public ConfigurationCreator(
1819
IServiceProviderConfigurationCreator serviceProviderConfigCreator,
1920
IQoSOptionsCreator qosOptionsCreator,
2021
IHttpHandlerOptionsCreator httpHandlerOptionsCreator,
2122
IServiceProvider serviceProvider,
22-
ILoadBalancerOptionsCreator loadBalancerOptionsCreator
23+
ILoadBalancerOptionsCreator loadBalancerOptionsCreator,
24+
IVersionCreator versionCreator
2325
)
2426
{
2527
_adminPath = serviceProvider.GetService<IAdministrationPath>();
2628
_loadBalancerOptionsCreator = loadBalancerOptionsCreator;
2729
_serviceProviderConfigCreator = serviceProviderConfigCreator;
2830
_qosOptionsCreator = qosOptionsCreator;
2931
_httpHandlerOptionsCreator = httpHandlerOptionsCreator;
32+
_versionCreator = versionCreator;
3033
}
3134

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

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

47+
var version = _versionCreator.Create(fileConfiguration.GlobalConfiguration.DownstreamHttpVersion);
48+
4449
return new InternalConfiguration(reRoutes,
4550
adminPath,
4651
serviceProviderConfiguration,
4752
fileConfiguration.GlobalConfiguration.RequestIdKey,
4853
lbOptions,
4954
fileConfiguration.GlobalConfiguration.DownstreamScheme,
5055
qosOptions,
51-
httpHandlerOptions
56+
httpHandlerOptions,
57+
version
5258
);
5359
}
5460
}

src/Ocelot/Configuration/Creator/DynamicsCreator.cs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,12 @@ namespace Ocelot.Configuration.Creator
88
public class DynamicsCreator : IDynamicsCreator
99
{
1010
private readonly IRateLimitOptionsCreator _rateLimitOptionsCreator;
11+
private readonly IVersionCreator _versionCreator;
1112

12-
public DynamicsCreator(IRateLimitOptionsCreator rateLimitOptionsCreator)
13+
public DynamicsCreator(IRateLimitOptionsCreator rateLimitOptionsCreator, IVersionCreator versionCreator)
1314
{
1415
_rateLimitOptionsCreator = rateLimitOptionsCreator;
16+
_versionCreator = versionCreator;
1517
}
1618

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

31+
var version = _versionCreator.Create(fileDynamicReRoute.DownstreamHttpVersion);
32+
2933
var downstreamReRoute = new DownstreamReRouteBuilder()
3034
.WithEnableRateLimiting(rateLimitOption.EnableRateLimiting)
3135
.WithRateLimitOptions(rateLimitOption)
3236
.WithServiceName(fileDynamicReRoute.ServiceName)
37+
.WithDownstreamHttpVersion(version)
3338
.Build();
3439

3540
var reRoute = new ReRouteBuilder()
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
namespace Ocelot.Configuration.Creator
2+
{
3+
using System;
4+
5+
public class HttpVersionCreator : IVersionCreator
6+
{
7+
public Version Create(string downstreamHttpVersion)
8+
{
9+
if (!Version.TryParse(downstreamHttpVersion, out Version version))
10+
{
11+
version = new Version(1, 1);
12+
}
13+
14+
return version;
15+
}
16+
}
17+
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
namespace Ocelot.Configuration.Creator
2+
{
3+
using System;
4+
5+
public interface IVersionCreator
6+
{
7+
Version Create(string downstreamHttpVersion);
8+
}
9+
}

src/Ocelot/Configuration/Creator/ReRoutesCreator.cs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ public class ReRoutesCreator : IReRoutesCreator
2222
private readonly IDownstreamAddressesCreator _downstreamAddressesCreator;
2323
private readonly IReRouteKeyCreator _reRouteKeyCreator;
2424
private readonly ISecurityOptionsCreator _securityOptionsCreator;
25+
private readonly IVersionCreator _versionCreator;
2526

2627
public ReRoutesCreator(
2728
IClaimsToThingCreator claimsToThingCreator,
@@ -37,7 +38,8 @@ public ReRoutesCreator(
3738
IDownstreamAddressesCreator downstreamAddressesCreator,
3839
ILoadBalancerOptionsCreator loadBalancerOptionsCreator,
3940
IReRouteKeyCreator reRouteKeyCreator,
40-
ISecurityOptionsCreator securityOptionsCreator
41+
ISecurityOptionsCreator securityOptionsCreator,
42+
IVersionCreator versionCreator
4143
)
4244
{
4345
_reRouteKeyCreator = reRouteKeyCreator;
@@ -55,6 +57,7 @@ ISecurityOptionsCreator securityOptionsCreator
5557
_httpHandlerOptionsCreator = httpHandlerOptionsCreator;
5658
_loadBalancerOptionsCreator = loadBalancerOptionsCreator;
5759
_securityOptionsCreator = securityOptionsCreator;
60+
_versionCreator = versionCreator;
5861
}
5962

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

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

110+
var downstreamHttpVersion = _versionCreator.Create(fileReRoute.DownstreamHttpVersion);
111+
107112
var reRoute = new DownstreamReRouteBuilder()
108113
.WithKey(fileReRoute.Key)
109114
.WithDownstreamPathTemplate(fileReRoute.DownstreamPathTemplate)
@@ -138,6 +143,7 @@ private DownstreamReRoute SetUpDownstreamReRoute(FileReRoute fileReRoute, FileGl
138143
.WithAddHeadersToUpstream(hAndRs.AddHeadersToUpstream)
139144
.WithDangerousAcceptAnyServerCertificateValidator(fileReRoute.DangerousAcceptAnyServerCertificateValidator)
140145
.WithSecurityOptions(securityOptions)
146+
.WithDownstreamHttpVersion(downstreamHttpVersion)
141147
.WithDownStreamHttpMethod(fileReRoute.DownstreamHttpMethod)
142148
.Build();
143149

src/Ocelot/Configuration/DownstreamReRoute.cs

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
namespace Ocelot.Configuration
22
{
33
using Creator;
4+
using System;
45
using System.Collections.Generic;
56
using Values;
67

@@ -39,7 +40,8 @@ public DownstreamReRoute(
3940
List<AddHeader> addHeadersToUpstream,
4041
bool dangerousAcceptAnyServerCertificateValidator,
4142
SecurityOptions securityOptions,
42-
string downstreamHttpMethod)
43+
string downstreamHttpMethod,
44+
Version downstreamHttpVersion)
4345
{
4446
DangerousAcceptAnyServerCertificateValidator = dangerousAcceptAnyServerCertificateValidator;
4547
AddHeadersToDownstream = addHeadersToDownstream;
@@ -74,6 +76,7 @@ public DownstreamReRoute(
7476
AddHeadersToUpstream = addHeadersToUpstream;
7577
SecurityOptions = securityOptions;
7678
DownstreamHttpMethod = downstreamHttpMethod;
79+
DownstreamHttpVersion = downstreamHttpVersion;
7780
}
7881

7982
public string Key { get; }
@@ -109,5 +112,6 @@ public DownstreamReRoute(
109112
public bool DangerousAcceptAnyServerCertificateValidator { get; }
110113
public SecurityOptions SecurityOptions { get; }
111114
public string DownstreamHttpMethod { get; }
115+
public Version DownstreamHttpVersion { get; }
112116
}
113117
}

src/Ocelot/Configuration/File/FileDynamicReRoute.cs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@ public class FileDynamicReRoute
44
{
55
public string ServiceName { get; set; }
66
public FileRateLimitRule RateLimitRule { get; set; }
7+
public string DownstreamHttpVersion { get; set; }
78
}
89
}

src/Ocelot/Configuration/File/FileGlobalConfiguration.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,5 +26,7 @@ public FileGlobalConfiguration()
2626
public string DownstreamScheme { get; set; }
2727

2828
public FileHttpHandlerOptions HttpHandlerOptions { get; set; }
29+
30+
public string DownstreamHttpVersion { get; set; }
2931
}
3032
}

0 commit comments

Comments
 (0)