实现根据请求端口增加相应头

This commit is contained in:
token
2024-01-24 18:34:12 +08:00
parent e2bd7a4db3
commit 929ebce1a7
3 changed files with 6 additions and 6 deletions
+2 -1
View File
@@ -23,4 +23,5 @@ global using System.Security.Claims;
global using Microsoft.AspNetCore.Server.Kestrel.Core;
global using System.Text;
global using Microsoft.IdentityModel.Tokens;
global using System.Collections.Concurrent;
global using System.Collections.Concurrent;
global using Microsoft.AspNetCore.Http.Features;
@@ -4,6 +4,7 @@ public class StaticFileProxyMiddleware(IContentTypeProvider contentTypeProvider)
{
public async Task InvokeAsync(HttpContext context, RequestDelegate next)
{
context.Response.Headers["Alt-Svc"] = "h3=\":" + context.Request.Host.Port + "\"";
// 如果是非GET请求,则直接跳过, /api/gateway/开头的请求也跳过 这个是属于系统内置的接口
if ((context.Request.Method != "GET" && StaticFileProxyService.StaticFileProxyEntityList.Count == 0) ||
context.Request.Path.Value?.StartsWith("/api/gateway/") == true)
@@ -72,7 +73,7 @@ public class StaticFileProxyMiddleware(IContentTypeProvider contentTypeProvider)
return;
}
readfile:
readfile:
// 获取文件的ContentType
context.Response.ContentType = contentTypeProvider.TryGetContentType(filePath, out var contentType)
+2 -4
View File
@@ -1,7 +1,5 @@
#region FreeSql类型转换
using Microsoft.AspNetCore.Http.Features;
Utils.TypeHandlers.TryAdd(typeof(Dictionary<string, string>), new StringJsonHandler<Dictionary<string, string>>());
Utils.TypeHandlers.TryAdd(typeof(RouteMatchEntity), new StringJsonHandler<RouteMatchEntity>());
Utils.TypeHandlers.TryAdd(typeof(List<DestinationsEntity>), new StringJsonHandler<List<DestinationsEntity>>());
@@ -23,7 +21,7 @@ builder.WebHost.UseKestrel(options =>
{
// 从Certificate服务中获取
if (string.IsNullOrEmpty(name) ||
!CertificateService.CertificateEntityDict.TryGetValue(name, out var certificate)) return null;
!CertificateService.CertificateEntityDict.TryGetValue(name, out var certificate)) return new X509Certificate2();
var path = Path.Combine("/data/", certificate.Path);
@@ -46,7 +44,7 @@ builder.WebHost.ConfigureKestrel(kestrel =>
portOptions.Protocols = HttpProtocols.Http1AndHttp2AndHttp3;
portOptions.UseHttps();
});
kestrel.ListenAnyIP(8080, portOptions =>
{
portOptions.Protocols = HttpProtocols.Http1AndHttp2;