fix middleware bug
This commit is contained in:
@@ -4,13 +4,30 @@ public class SimApiJobOptions
|
|||||||
{
|
{
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// WebUi地址,设置为null表示不启用
|
/// WebUi地址,设置为null表示不启用
|
||||||
|
/// 默认 /jobs
|
||||||
/// </summary>
|
/// </summary>
|
||||||
public string? DashboardUrl { get; set; } = "/jobs";
|
public string? DashboardUrl { get; set; } = "/jobs";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// webui 用户
|
||||||
|
/// 默认 admin
|
||||||
|
/// </summary>
|
||||||
public string DashboardAuthUser { get; set; } = "admin";
|
public string DashboardAuthUser { get; set; } = "admin";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// webui 密码
|
||||||
|
/// 默认 Admin@123!
|
||||||
|
/// </summary>
|
||||||
public string DashboardAuthPass { get; set; } = "Admin@123!";
|
public string DashboardAuthPass { get; set; } = "Admin@123!";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置为null 使用默认redis配置
|
||||||
|
/// </summary>
|
||||||
public string? RedisConfiguration { get; set; }
|
public string? RedisConfiguration { get; set; }
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// 设置为null 使用默认redis配置
|
||||||
|
/// </summary>
|
||||||
public int? Database { get; set; } = null;
|
public int? Database { get; set; } = null;
|
||||||
public SimApiJobServerConfig[] Servers { get; set; } = [new()];
|
public SimApiJobServerConfig[] Servers { get; set; } = [new()];
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -11,7 +11,7 @@ public class SimApiJobWebAuth(string user, string pass) : IDashboardAuthorizatio
|
|||||||
public bool Authorize(DashboardContext context)
|
public bool Authorize(DashboardContext context)
|
||||||
{
|
{
|
||||||
var httpContext = context.GetHttpContext();
|
var httpContext = context.GetHttpContext();
|
||||||
var authHeader = httpContext.Request.Headers["Authorization"].FirstOrDefault();
|
var authHeader = httpContext.Request.Headers.Authorization.FirstOrDefault();
|
||||||
if (authHeader != null && authHeader.StartsWith("Basic "))
|
if (authHeader != null && authHeader.StartsWith("Basic "))
|
||||||
{
|
{
|
||||||
var encodedUsernamePassword = authHeader.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries)[1].Trim();
|
var encodedUsernamePassword = authHeader.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries)[1].Trim();
|
||||||
|
|||||||
@@ -24,16 +24,19 @@ public class SimApiExceptionMiddleware(RequestDelegate next, ILogger<SimApiExcep
|
|||||||
try
|
try
|
||||||
{
|
{
|
||||||
await next(context);
|
await next(context);
|
||||||
switch (context.Response.StatusCode)
|
if (!context.Response.HasStarted)
|
||||||
{
|
{
|
||||||
case 200:
|
switch (context.Response.StatusCode)
|
||||||
case 301:
|
{
|
||||||
case 302:
|
case 200:
|
||||||
break;
|
case 301:
|
||||||
case 404:
|
case 302:
|
||||||
throw new SimApiException(context.Response.StatusCode, "请求的接口不存在");
|
break;
|
||||||
default:
|
case 404:
|
||||||
throw new SimApiException(context.Response.StatusCode);
|
throw new SimApiException(context.Response.StatusCode, "请求的接口不存在");
|
||||||
|
default:
|
||||||
|
throw new SimApiException(context.Response.StatusCode);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (SimApiException ex)
|
catch (SimApiException ex)
|
||||||
|
|||||||
Reference in New Issue
Block a user