From 49fdeadfd22ac3c85a13ff1a378cbc84e42ff42e Mon Sep 17 00:00:00 2001 From: RMBGAME Date: Mon, 1 Jul 2024 15:08:46 +0800 Subject: [PATCH] =?UTF-8?q?=F0=9F=90=9B=20HttpVersion=20=E5=9B=A0=E6=8C=89?= =?UTF-8?q?=E5=8E=9F=E6=9C=AC=E9=80=BB=E8=BE=91=E8=BD=AC=E5=8F=91?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Middleware/HttpReverseProxyMiddleware.cs | 31 ++++++++++++------- 1 file changed, 20 insertions(+), 11 deletions(-) diff --git a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/HttpServer/Middleware/HttpReverseProxyMiddleware.cs b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/HttpServer/Middleware/HttpReverseProxyMiddleware.cs index 5b0f584a2..5b1f8fd18 100644 --- a/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/HttpServer/Middleware/HttpReverseProxyMiddleware.cs +++ b/src/BD.WTTS.Client.Plugins.Accelerator.ReverseProxy/Services.Implementation/HttpServer/Middleware/HttpReverseProxyMiddleware.cs @@ -57,7 +57,16 @@ sealed partial class HttpReverseProxyMiddleware { var httpClient = httpClientFactory.CreateHttpClient("GlobalProxy", defaultDomainConfig); var destinationPrefix = GetDestinationPrefix(context.Request.Scheme, context.Request.Host, null); - var error = await httpForwarder.SendAsync(context, destinationPrefix, httpClient, ForwarderRequestConfig.Empty, HttpTransformer.Empty); + var forwarderRequestConfig = new ForwarderRequestConfig() + { + Version = context.Request.Protocol switch + { + var protocol when protocol.StartsWith("HTTP/2") => System.Net.HttpVersion.Version20, + var protocol when protocol.StartsWith("HTTP/3") => System.Net.HttpVersion.Version30, + _ => System.Net.HttpVersion.Version11, + }, + }; + var error = await httpForwarder.SendAsync(context, destinationPrefix, httpClient, forwarderRequestConfig, HttpTransformer.Empty); if (error != ForwarderError.None) { await HandleErrorAsync(context, error); @@ -109,22 +118,22 @@ sealed partial class HttpReverseProxyMiddleware context.Request.Headers.UserAgent = domainConfig.UserAgent.Replace("${origin}", context.Request.Headers.UserAgent, StringComparison.OrdinalIgnoreCase); } - //var forwarderRequestConfig = new ForwarderRequestConfig() - //{ - // Version = context.Request.Protocol switch - // { - // var protocol when protocol.StartsWith("HTTP/2") => System.Net.HttpVersion.Version20, - // var protocol when protocol.StartsWith("HTTP/3") => System.Net.HttpVersion.Version30, - // _ => System.Net.HttpVersion.Version11, - // }, - //}; + var forwarderRequestConfig = new ForwarderRequestConfig() + { + Version = context.Request.Protocol switch + { + var protocol when protocol.StartsWith("HTTP/2") => System.Net.HttpVersion.Version20, + var protocol when protocol.StartsWith("HTTP/3") => System.Net.HttpVersion.Version30, + _ => System.Net.HttpVersion.Version11, + }, + }; if (domainConfig.IsServerSideProxy) { SetWattHeaders(context, reverseProxyConfig.Service.ServerSideProxyToken); } - var error = await httpForwarder.SendAsync(context, destinationPrefix, httpClient, ForwarderRequestConfig.Empty, HttpTransformer.Empty); + var error = await httpForwarder.SendAsync(context, destinationPrefix, httpClient, forwarderRequestConfig, HttpTransformer.Empty); if (error != ForwarderError.None) {