Skip to content

Commit

Permalink
🐛 HttpVersion 因按原本逻辑转发
Browse files Browse the repository at this point in the history
  • Loading branch information
rmbadmin committed Jul 1, 2024
1 parent bca8024 commit 49fdead
Showing 1 changed file with 20 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,16 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
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);
Expand Down Expand Up @@ -109,22 +118,22 @@ public async Task InvokeAsync(HttpContext context, RequestDelegate next)
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)
{
Expand Down

0 comments on commit 49fdead

Please sign in to comment.