mirror of
				https://github.com/nsnail/Ocelot.git
				synced 2025-11-04 15:10:50 +08:00 
			
		
		
		
	Add DownstreamHttpVersion property for Http/2 WebServer
This commit is contained in:
		@@ -1,5 +1,6 @@
 | 
			
		||||
using Ocelot.Configuration.Creator;
 | 
			
		||||
using Ocelot.Values;
 | 
			
		||||
using System;
 | 
			
		||||
using System.Collections.Generic;
 | 
			
		||||
using System.Linq;
 | 
			
		||||
using System.Net.Http;
 | 
			
		||||
@@ -42,6 +43,7 @@ namespace Ocelot.Configuration.Builder
 | 
			
		||||
        private bool _dangerousAcceptAnyServerCertificateValidator;
 | 
			
		||||
        private SecurityOptions _securityOptions;
 | 
			
		||||
        private string _downstreamHttpMethod;
 | 
			
		||||
        private string _downstreamHttpVersion;
 | 
			
		||||
 | 
			
		||||
        public DownstreamReRouteBuilder()
 | 
			
		||||
        {
 | 
			
		||||
@@ -255,6 +257,12 @@ namespace Ocelot.Configuration.Builder
 | 
			
		||||
            return this;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public DownstreamReRouteBuilder WithHttpVersion(string httpVersion)
 | 
			
		||||
        {
 | 
			
		||||
            _downstreamHttpVersion = httpVersion;
 | 
			
		||||
            return this;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public DownstreamReRoute Build()
 | 
			
		||||
        {
 | 
			
		||||
            return new DownstreamReRoute(
 | 
			
		||||
@@ -290,7 +298,8 @@ namespace Ocelot.Configuration.Builder
 | 
			
		||||
                _addHeadersToUpstream,
 | 
			
		||||
                _dangerousAcceptAnyServerCertificateValidator,
 | 
			
		||||
                _securityOptions,
 | 
			
		||||
                _downstreamHttpMethod);
 | 
			
		||||
                _downstreamHttpMethod,
 | 
			
		||||
                _downstreamHttpVersion);
 | 
			
		||||
        }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -138,6 +138,7 @@ namespace Ocelot.Configuration.Creator
 | 
			
		||||
                .WithAddHeadersToUpstream(hAndRs.AddHeadersToUpstream)
 | 
			
		||||
                .WithDangerousAcceptAnyServerCertificateValidator(fileReRoute.DangerousAcceptAnyServerCertificateValidator)
 | 
			
		||||
                .WithSecurityOptions(securityOptions)
 | 
			
		||||
                .WithHttpVersion(fileReRoute.DownstreamHttpVersion)
 | 
			
		||||
                .WithDownStreamHttpMethod(fileReRoute.DownstreamHttpMethod)
 | 
			
		||||
                .Build();
 | 
			
		||||
 | 
			
		||||
 
 | 
			
		||||
@@ -1,6 +1,7 @@
 | 
			
		||||
namespace Ocelot.Configuration
 | 
			
		||||
{
 | 
			
		||||
    using Creator;
 | 
			
		||||
    using System;
 | 
			
		||||
    using System.Collections.Generic;
 | 
			
		||||
    using Values;
 | 
			
		||||
 | 
			
		||||
@@ -39,7 +40,8 @@ namespace Ocelot.Configuration
 | 
			
		||||
            List<AddHeader> addHeadersToUpstream,
 | 
			
		||||
            bool dangerousAcceptAnyServerCertificateValidator,
 | 
			
		||||
            SecurityOptions securityOptions,
 | 
			
		||||
            string downstreamHttpMethod)
 | 
			
		||||
            string downstreamHttpMethod,
 | 
			
		||||
            string downstreamHttpVersion)
 | 
			
		||||
        {
 | 
			
		||||
            DangerousAcceptAnyServerCertificateValidator = dangerousAcceptAnyServerCertificateValidator;
 | 
			
		||||
            AddHeadersToDownstream = addHeadersToDownstream;
 | 
			
		||||
@@ -74,6 +76,7 @@ namespace Ocelot.Configuration
 | 
			
		||||
            AddHeadersToUpstream = addHeadersToUpstream;
 | 
			
		||||
            SecurityOptions = securityOptions;
 | 
			
		||||
            DownstreamHttpMethod = downstreamHttpMethod;
 | 
			
		||||
            DownstreamHttpVersion = downstreamHttpVersion;
 | 
			
		||||
        }
 | 
			
		||||
 | 
			
		||||
        public string Key { get; }
 | 
			
		||||
@@ -109,5 +112,6 @@ namespace Ocelot.Configuration
 | 
			
		||||
        public bool DangerousAcceptAnyServerCertificateValidator { get; }
 | 
			
		||||
        public SecurityOptions SecurityOptions { get; }
 | 
			
		||||
        public string DownstreamHttpMethod { get; }
 | 
			
		||||
        public string DownstreamHttpVersion { get;  }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -56,5 +56,6 @@ namespace Ocelot.Configuration.File
 | 
			
		||||
        public int Timeout { get; set; }
 | 
			
		||||
        public bool DangerousAcceptAnyServerCertificateValidator { get; set; }
 | 
			
		||||
        public FileSecurityOptions SecurityOptions { get; set; }
 | 
			
		||||
        public string DownstreamHttpVersion { get; set; }
 | 
			
		||||
    }
 | 
			
		||||
}
 | 
			
		||||
 
 | 
			
		||||
@@ -83,6 +83,11 @@
 | 
			
		||||
                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)
 | 
			
		||||
 
 | 
			
		||||
@@ -20,11 +20,17 @@
 | 
			
		||||
        {
 | 
			
		||||
            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)
 | 
			
		||||
                    RequestUri = MapUri(request),
 | 
			
		||||
                    Version = version,
 | 
			
		||||
                };
 | 
			
		||||
 | 
			
		||||
                MapHeaders(request, requestMessage);
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user