Skip to content

Commit c448381

Browse files
committed
fix middleware bug
1 parent 8d5b667 commit c448381

3 files changed

Lines changed: 30 additions & 10 deletions

File tree

Configurations/SimApiJobOptions.cs

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,30 @@ public class SimApiJobOptions
44
{
55
/// <summary>
66
/// WebUi地址,设置为null表示不启用
7+
/// 默认 /jobs
78
/// </summary>
89
public string? DashboardUrl { get; set; } = "/jobs";
910

11+
/// <summary>
12+
/// webui 用户
13+
/// 默认 admin
14+
/// </summary>
1015
public string DashboardAuthUser { get; set; } = "admin";
16+
17+
/// <summary>
18+
/// webui 密码
19+
/// 默认 Admin@123!
20+
/// </summary>
1121
public string DashboardAuthPass { get; set; } = "Admin@123!";
22+
23+
/// <summary>
24+
/// 设置为null 使用默认redis配置
25+
/// </summary>
1226
public string? RedisConfiguration { get; set; }
1327

28+
/// <summary>
29+
/// 设置为null 使用默认redis配置
30+
/// </summary>
1431
public int? Database { get; set; } = null;
1532
public SimApiJobServerConfig[] Servers { get; set; } = [new()];
1633
}

Helpers/SimApiJobWebAuth.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ public class SimApiJobWebAuth(string user, string pass) : IDashboardAuthorizatio
1111
public bool Authorize(DashboardContext context)
1212
{
1313
var httpContext = context.GetHttpContext();
14-
var authHeader = httpContext.Request.Headers["Authorization"].FirstOrDefault();
14+
var authHeader = httpContext.Request.Headers.Authorization.FirstOrDefault();
1515
if (authHeader != null && authHeader.StartsWith("Basic "))
1616
{
1717
var encodedUsernamePassword = authHeader.Split(' ', 2, StringSplitOptions.RemoveEmptyEntries)[1].Trim();

Middlewares/SimApiExceptionMiddleware.cs

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -24,16 +24,19 @@ public async Task InvokeAsync(HttpContext context)
2424
try
2525
{
2626
await next(context);
27-
switch (context.Response.StatusCode)
27+
if (!context.Response.HasStarted)
2828
{
29-
case 200:
30-
case 301:
31-
case 302:
32-
break;
33-
case 404:
34-
throw new SimApiException(context.Response.StatusCode, "请求的接口不存在");
35-
default:
36-
throw new SimApiException(context.Response.StatusCode);
29+
switch (context.Response.StatusCode)
30+
{
31+
case 200:
32+
case 301:
33+
case 302:
34+
break;
35+
case 404:
36+
throw new SimApiException(context.Response.StatusCode, "请求的接口不存在");
37+
default:
38+
throw new SimApiException(context.Response.StatusCode);
39+
}
3740
}
3841
}
3942
catch (SimApiException ex)

0 commit comments

Comments
 (0)