增加ResponseConfig

This commit is contained in:
xljiulang 2021-07-18 12:24:54 +08:00
parent 4c16557e4b
commit f374554c78
4 changed files with 53 additions and 12 deletions

View File

@ -5,22 +5,27 @@ namespace FastGithub
/// <summary> /// <summary>
/// 域名配置 /// 域名配置
/// </summary> /// </summary>
public class DomainConfig public record DomainConfig
{ {
/// <summary> /// <summary>
/// 是否发送SNI /// 是否发送SNI
/// </summary> /// </summary>
public bool TlsSni { get; set; } public bool TlsSni { get; init; }
/// <summary> /// <summary>
/// 请求超时时长 /// 请求超时时长
/// </summary> /// </summary>
public TimeSpan? Timeout { get; set; } public TimeSpan? Timeout { get; init; }
/// <summary> /// <summary>
/// 目的地 /// 目的地
/// 格式为相对或绝对uri /// 格式为相对或绝对uri
/// </summary> /// </summary>
public Uri? Destination { get; set; } public Uri? Destination { get; init; }
/// <summary>
/// 自定义响应
/// </summary>
public ResponseConfig? Response { get; init; }
} }
} }

View 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; }
}
}

View File

@ -46,6 +46,15 @@ namespace FastGithub.ReverseProxy
context.Response.ContentType = "text/html"; context.Response.ContentType = "text/html";
await context.Response.SendFileAsync(fallbackFile); 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 else
{ {
var destinationPrefix = GetDestinationPrefix(host, domainConfig.Destination); var destinationPrefix = GetDestinationPrefix(host, domainConfig.Destination);

View File

@ -1,18 +1,18 @@
{ {
"FastGithub": { "FastGithub": {
"PureDns": { // DomainConfigs "PureDns": { // DomainConfigs
"IPAddress": "127.0.0.1", "IPAddress": "127.0.0.1",
"Port": 5533 // 5533dnscrypt-proxy "Port": 5533 // 5533dnscrypt-proxy
}, },
"FastDns": { // DomainConfigs "FastDns": { // DomainConfigs
"IPAddress": "114.114.114.114", "IPAddress": "114.114.114.114",
"Port": 53 "Port": 53
}, },
"DomainConfigs": { // *0 "DomainConfigs": { // *0
"github.com": { "github.com": {
"TlsSni": false, // tlsSNI "TlsSni": false, // tlsSNI
"Timeout": null, // "00:02:00"null "Timeout": null, // "00:02:00"null
"Destination": null // Urinull "Destination": null // Urinull
}, },
"githubstatus.com": { "githubstatus.com": {
"TlsSni": false "TlsSni": false
@ -60,7 +60,11 @@
"Destination": "https://fdn.geekzu.org/" "Destination": "https://fdn.geekzu.org/"
}, },
"i.stack.imgur.com": { "i.stack.imgur.com": {
"Destination": "http://localhost/" // "Response": { //
"StatusCode": 404,
"ContentType": "text/plain;charset=utf-8",
"ContentValue": "阻断的请求"
}
} }
} }
}, },