增加ResponseConfig
This commit is contained in:
parent
4c16557e4b
commit
f374554c78
@ -5,22 +5,27 @@ namespace FastGithub
|
||||
/// <summary>
|
||||
/// 域名配置
|
||||
/// </summary>
|
||||
public class DomainConfig
|
||||
public record DomainConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 是否发送SNI
|
||||
/// </summary>
|
||||
public bool TlsSni { get; set; }
|
||||
public bool TlsSni { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 请求超时时长
|
||||
/// </summary>
|
||||
public TimeSpan? Timeout { get; set; }
|
||||
public TimeSpan? Timeout { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 目的地
|
||||
/// 格式为相对或绝对uri
|
||||
/// </summary>
|
||||
public Uri? Destination { get; set; }
|
||||
public Uri? Destination { get; init; }
|
||||
|
||||
/// <summary>
|
||||
/// 自定义响应
|
||||
/// </summary>
|
||||
public ResponseConfig? Response { get; init; }
|
||||
}
|
||||
}
|
||||
|
||||
23
FastGithub.Core/ResponseConfig.cs
Normal file
23
FastGithub.Core/ResponseConfig.cs
Normal file
@ -0,0 +1,23 @@
|
||||
namespace FastGithub
|
||||
{
|
||||
/// <summary>
|
||||
/// 响应配置
|
||||
/// </summary>
|
||||
public record ResponseConfig
|
||||
{
|
||||
/// <summary>
|
||||
/// 状态码
|
||||
/// </summary>
|
||||
public int StatusCode { get; init; } = 200;
|
||||
|
||||
/// <summary>
|
||||
/// 内容类型
|
||||
/// </summary>
|
||||
public string ContentType { get; init; } = "text/plain;charset=utf-8";
|
||||
|
||||
/// <summary>
|
||||
/// 内容的值
|
||||
/// </summary>
|
||||
public string? ContentValue { get; init; }
|
||||
}
|
||||
}
|
||||
@ -46,6 +46,15 @@ namespace FastGithub.ReverseProxy
|
||||
context.Response.ContentType = "text/html";
|
||||
await context.Response.SendFileAsync(fallbackFile);
|
||||
}
|
||||
else if (domainConfig.Response != null)
|
||||
{
|
||||
context.Response.StatusCode = domainConfig.Response.StatusCode;
|
||||
context.Response.ContentType = domainConfig.Response.ContentType;
|
||||
if (domainConfig.Response.ContentValue != null)
|
||||
{
|
||||
await context.Response.WriteAsync(domainConfig.Response.ContentValue);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
var destinationPrefix = GetDestinationPrefix(host, domainConfig.Destination);
|
||||
|
||||
@ -1,18 +1,18 @@
|
||||
{
|
||||
"FastGithub": {
|
||||
"PureDns": { // 用于解析DomainConfigs的域名
|
||||
"PureDns": { // 用于解析DomainConfigs的域名
|
||||
"IPAddress": "127.0.0.1",
|
||||
"Port": 5533 // 5533指向dnscrypt-proxy
|
||||
"Port": 5533 // 5533指向dnscrypt-proxy
|
||||
},
|
||||
"FastDns": { // 用于解析不在DomainConfigs的域名
|
||||
"FastDns": { // 用于解析不在DomainConfigs的域名
|
||||
"IPAddress": "114.114.114.114",
|
||||
"Port": 53
|
||||
},
|
||||
"DomainConfigs": { // 域名的*表示0到多个任意字符
|
||||
"DomainConfigs": { // 域名的*表示0到多个任意字符
|
||||
"github.com": {
|
||||
"TlsSni": false, // 指示tls握手时是否发送SNI
|
||||
"Timeout": null, // 请求超时时长,格式为"00:02:00",默认为null
|
||||
"Destination": null // 请求目的地,格式为绝对或相对Uri,默认null
|
||||
"TlsSni": false, // 指示tls握手时是否发送SNI
|
||||
"Timeout": null, // 请求超时时长,格式为"00:02:00",默认为null
|
||||
"Destination": null // 请求目的地,格式为绝对或相对Uri,默认null
|
||||
},
|
||||
"githubstatus.com": {
|
||||
"TlsSni": false
|
||||
@ -60,7 +60,11 @@
|
||||
"Destination": "https://fdn.geekzu.org/"
|
||||
},
|
||||
"i.stack.imgur.com": {
|
||||
"Destination": "http://localhost/" // 没有对应的资源,阻断请求
|
||||
"Response": { // 直接响应
|
||||
"StatusCode": 404,
|
||||
"ContentType": "text/plain;charset=utf-8",
|
||||
"ContentValue": "阻断的请求"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
Loading…
Reference in New Issue
Block a user