- GwRouteMatch: 路由匹配配置值对象(Path, Methods, Hosts, Headers, QueryParameters) - GwRouteHeader: Header 匹配规则值对象 - GwRouteQueryParameter: 查询参数匹配规则值对象 - GwLoadBalancingPolicy: 负载均衡策略枚举 - GwTransform: 请求/响应转换规则值对象 - EF Core 使用 ToJson() 将值对象映射为 JSON 列
77 lines
2.1 KiB
C#
77 lines
2.1 KiB
C#
namespace Fengling.Platform.Domain.AggregatesModel.GatewayAggregate;
|
|
|
|
/// <summary>
|
|
/// 请求/响应转换规则(值对象)
|
|
/// 以 JSON 列存储在数据库中
|
|
/// </summary>
|
|
public class GwTransform
|
|
{
|
|
/// <summary>
|
|
/// 转换规则键值对
|
|
/// 例如: {"RequestHeader": "X-Custom-Header", "Set": "value"}
|
|
/// </summary>
|
|
public Dictionary<string, string> Rules { get; set; } = new();
|
|
}
|
|
|
|
/// <summary>
|
|
/// 常用转换规则工厂
|
|
/// </summary>
|
|
public static class GwTransforms
|
|
{
|
|
/// <summary>
|
|
/// 设置请求头
|
|
/// </summary>
|
|
public static GwTransform SetRequestHeader(string headerName, string value)
|
|
=> new() { Rules = new Dictionary<string, string>
|
|
{
|
|
{ "RequestHeader", headerName },
|
|
{ "Set", value }
|
|
}};
|
|
|
|
/// <summary>
|
|
/// 添加请求头
|
|
/// </summary>
|
|
public static GwTransform AppendRequestHeader(string headerName, string value)
|
|
=> new() { Rules = new Dictionary<string, string>
|
|
{
|
|
{ "RequestHeader", headerName },
|
|
{ "Append", value }
|
|
}};
|
|
|
|
/// <summary>
|
|
/// 设置响应头
|
|
/// </summary>
|
|
public static GwTransform SetResponseHeader(string headerName, string value)
|
|
=> new() { Rules = new Dictionary<string, string>
|
|
{
|
|
{ "ResponseHeader", headerName },
|
|
{ "Set", value }
|
|
}};
|
|
|
|
/// <summary>
|
|
/// 移除路径前缀
|
|
/// </summary>
|
|
public static GwTransform PathRemovePrefix(string prefix)
|
|
=> new() { Rules = new Dictionary<string, string>
|
|
{
|
|
{ "PathRemovePrefix", prefix }
|
|
}};
|
|
|
|
/// <summary>
|
|
/// 设置路径前缀
|
|
/// </summary>
|
|
public static GwTransform PathSetPrefix(string prefix)
|
|
=> new() { Rules = new Dictionary<string, string>
|
|
{
|
|
{ "PathPrefix", prefix }
|
|
}};
|
|
|
|
/// <summary>
|
|
/// 使用原始 Host 头
|
|
/// </summary>
|
|
public static GwTransform RequestHeaderOriginalHost()
|
|
=> new() { Rules = new Dictionary<string, string>
|
|
{
|
|
{ "RequestHeaderOriginalHost", "true" }
|
|
}};
|
|
} |