Add DownstreamHttpVersion property for Http/2 WebServer

This commit is contained in:
Andrea Tosato 2020-02-10 18:01:54 +01:00
parent fc3b6fdb8b
commit f2f583a88c
6 changed files with 29 additions and 3 deletions

View File

@ -1,5 +1,6 @@
using Ocelot.Configuration.Creator; using Ocelot.Configuration.Creator;
using Ocelot.Values; using Ocelot.Values;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Net.Http; using System.Net.Http;
@ -42,6 +43,7 @@ namespace Ocelot.Configuration.Builder
private bool _dangerousAcceptAnyServerCertificateValidator; private bool _dangerousAcceptAnyServerCertificateValidator;
private SecurityOptions _securityOptions; private SecurityOptions _securityOptions;
private string _downstreamHttpMethod; private string _downstreamHttpMethod;
private string _downstreamHttpVersion;
public DownstreamReRouteBuilder() public DownstreamReRouteBuilder()
{ {
@ -255,6 +257,12 @@ namespace Ocelot.Configuration.Builder
return this; return this;
} }
public DownstreamReRouteBuilder WithHttpVersion(string httpVersion)
{
_downstreamHttpVersion = httpVersion;
return this;
}
public DownstreamReRoute Build() public DownstreamReRoute Build()
{ {
return new DownstreamReRoute( return new DownstreamReRoute(
@ -290,7 +298,8 @@ namespace Ocelot.Configuration.Builder
_addHeadersToUpstream, _addHeadersToUpstream,
_dangerousAcceptAnyServerCertificateValidator, _dangerousAcceptAnyServerCertificateValidator,
_securityOptions, _securityOptions,
_downstreamHttpMethod); _downstreamHttpMethod,
_downstreamHttpVersion);
} }
} }
} }

View File

@ -138,6 +138,7 @@ namespace Ocelot.Configuration.Creator
.WithAddHeadersToUpstream(hAndRs.AddHeadersToUpstream) .WithAddHeadersToUpstream(hAndRs.AddHeadersToUpstream)
.WithDangerousAcceptAnyServerCertificateValidator(fileReRoute.DangerousAcceptAnyServerCertificateValidator) .WithDangerousAcceptAnyServerCertificateValidator(fileReRoute.DangerousAcceptAnyServerCertificateValidator)
.WithSecurityOptions(securityOptions) .WithSecurityOptions(securityOptions)
.WithHttpVersion(fileReRoute.DownstreamHttpVersion)
.WithDownStreamHttpMethod(fileReRoute.DownstreamHttpMethod) .WithDownStreamHttpMethod(fileReRoute.DownstreamHttpMethod)
.Build(); .Build();

View File

@ -1,6 +1,7 @@
namespace Ocelot.Configuration namespace Ocelot.Configuration
{ {
using Creator; using Creator;
using System;
using System.Collections.Generic; using System.Collections.Generic;
using Values; using Values;
@ -39,7 +40,8 @@ namespace Ocelot.Configuration
List<AddHeader> addHeadersToUpstream, List<AddHeader> addHeadersToUpstream,
bool dangerousAcceptAnyServerCertificateValidator, bool dangerousAcceptAnyServerCertificateValidator,
SecurityOptions securityOptions, SecurityOptions securityOptions,
string downstreamHttpMethod) string downstreamHttpMethod,
string downstreamHttpVersion)
{ {
DangerousAcceptAnyServerCertificateValidator = dangerousAcceptAnyServerCertificateValidator; DangerousAcceptAnyServerCertificateValidator = dangerousAcceptAnyServerCertificateValidator;
AddHeadersToDownstream = addHeadersToDownstream; AddHeadersToDownstream = addHeadersToDownstream;
@ -74,6 +76,7 @@ namespace Ocelot.Configuration
AddHeadersToUpstream = addHeadersToUpstream; AddHeadersToUpstream = addHeadersToUpstream;
SecurityOptions = securityOptions; SecurityOptions = securityOptions;
DownstreamHttpMethod = downstreamHttpMethod; DownstreamHttpMethod = downstreamHttpMethod;
DownstreamHttpVersion = downstreamHttpVersion;
} }
public string Key { get; } public string Key { get; }
@ -109,5 +112,6 @@ namespace Ocelot.Configuration
public bool DangerousAcceptAnyServerCertificateValidator { get; } public bool DangerousAcceptAnyServerCertificateValidator { get; }
public SecurityOptions SecurityOptions { get; } public SecurityOptions SecurityOptions { get; }
public string DownstreamHttpMethod { get; } public string DownstreamHttpMethod { get; }
public string DownstreamHttpVersion { get; }
} }
} }

View File

@ -56,5 +56,6 @@ namespace Ocelot.Configuration.File
public int Timeout { get; set; } public int Timeout { get; set; }
public bool DangerousAcceptAnyServerCertificateValidator { get; set; } public bool DangerousAcceptAnyServerCertificateValidator { get; set; }
public FileSecurityOptions SecurityOptions { get; set; } public FileSecurityOptions SecurityOptions { get; set; }
public string DownstreamHttpVersion { get; set; }
} }
} }

View File

@ -83,6 +83,11 @@
RuleForEach(reRoute => reRoute.DownstreamHostAndPorts) RuleForEach(reRoute => reRoute.DownstreamHostAndPorts)
.SetValidator(hostAndPortValidator); .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) private async Task<bool> IsSupportedAuthenticationProviders(FileAuthenticationOptions authenticationOptions, CancellationToken cancellationToken)

View File

@ -20,11 +20,17 @@
{ {
try try
{ {
if (!Version.TryParse(downstreamReRoute.DownstreamHttpVersion, out Version version))
{
version = new Version(1, 1);
}
var requestMessage = new HttpRequestMessage() var requestMessage = new HttpRequestMessage()
{ {
Content = await MapContent(request), Content = await MapContent(request),
Method = MapMethod(request, downstreamReRoute), Method = MapMethod(request, downstreamReRoute),
RequestUri = MapUri(request) RequestUri = MapUri(request),
Version = version,
}; };
MapHeaders(request, requestMessage); MapHeaders(request, requestMessage);