diff --git a/YarpGateway.slnx b/YarpGateway.slnx index 586dfed..f391d42 100644 --- a/YarpGateway.slnx +++ b/YarpGateway.slnx @@ -5,6 +5,9 @@ + + + diff --git a/src/Directory.Packages.props b/src/Directory.Packages.props index be76ff7..5d69c13 100644 --- a/src/Directory.Packages.props +++ b/src/Directory.Packages.props @@ -12,6 +12,10 @@ + + + + diff --git a/src/Fengling.Gateway.Plugin.Abstractions/Fengling.Gateway.Plugin.Abstractions.csproj b/src/Fengling.Gateway.Plugin.Abstractions/Fengling.Gateway.Plugin.Abstractions.csproj new file mode 100644 index 0000000..0c5abb0 --- /dev/null +++ b/src/Fengling.Gateway.Plugin.Abstractions/Fengling.Gateway.Plugin.Abstractions.csproj @@ -0,0 +1,14 @@ + + + + net10.0 + enable + enable + Fengling.Gateway.Plugin.Abstractions + + + + + + + diff --git a/src/Fengling.Gateway.Plugin.Abstractions/IGatewayPlugin.cs b/src/Fengling.Gateway.Plugin.Abstractions/IGatewayPlugin.cs new file mode 100644 index 0000000..ffa436e --- /dev/null +++ b/src/Fengling.Gateway.Plugin.Abstractions/IGatewayPlugin.cs @@ -0,0 +1,63 @@ +using Microsoft.AspNetCore.Http; +using Yarp.ReverseProxy.Configuration; +using Yarp.ReverseProxy.Model; + +namespace Fengling.Gateway.Plugin.Abstractions; + +/// +/// 插件基础接口 +/// +public interface IGatewayPlugin +{ + string Name { get; } + string Version { get; } + string? Description { get; } + + Task OnLoadAsync(); + Task OnUnloadAsync(); +} + +/// +/// 请求处理插件 +/// +public interface IRequestPlugin : IGatewayPlugin +{ + /// 请求到达网关前 + Task OnRequestAsync(HttpContext context); + + /// 路由决策后 + Task OnRouteMatchedAsync(HttpContext context, RouteConfig route); + + /// 转发到后端前 + Task OnForwardingAsync(HttpContext context, HttpRequestMessage request); +} + +/// +/// 响应处理插件 +/// +public interface IResponsePlugin : IGatewayPlugin +{ + /// 后端响应后 + Task OnBackendResponseAsync(HttpContext context, HttpResponseMessage response); + + /// 返回客户端前 + Task OnResponseFinalizingAsync(HttpContext context); +} + +/// +/// 路由转换插件 +/// +public interface IRouteTransformPlugin : IGatewayPlugin +{ + Task TransformRouteAsync(RouteConfig original, HttpContext context); +} + +/// +/// 负载均衡插件 +/// +public interface ILoadBalancePlugin : IGatewayPlugin +{ + Task SelectDestinationAsync( + IReadOnlyList destinations, + HttpContext context); +}