mirror of
https://github.com/Wei-Shaw/sub2api.git
synced 2026-09-21 14:19:18 +08:00
fix: treat allowed proxy quality statuses as pass not warn
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
aa69e3947d
commit
32ef471103
@@ -3339,12 +3339,13 @@ func runProxyQualityTarget(ctx context.Context, client *http.Client, target prox
|
||||
}
|
||||
|
||||
if _, ok := target.AllowedStatuses[resp.StatusCode]; ok {
|
||||
// 白名单内的状态码均代表目标可达:2xx 表示接口直接可用,
|
||||
// 401/405 等是无鉴权探测的预期结果,同样视为连通正常,不再扣分。
|
||||
item.Status = "pass"
|
||||
if resp.StatusCode >= http.StatusOK && resp.StatusCode < http.StatusMultipleChoices {
|
||||
item.Status = "pass"
|
||||
item.Message = fmt.Sprintf("HTTP %d", resp.StatusCode)
|
||||
} else {
|
||||
item.Status = "warn"
|
||||
item.Message = fmt.Sprintf("HTTP %d(目标可达,但鉴权或方法受限)", resp.StatusCode)
|
||||
item.Message = fmt.Sprintf("HTTP %d(目标可达)", resp.StatusCode)
|
||||
}
|
||||
return item
|
||||
}
|
||||
|
||||
@@ -72,7 +72,7 @@ func TestRunProxyQualityTarget_AllowedStatusPass(t *testing.T) {
|
||||
require.Equal(t, http.StatusOK, item.HTTPStatus)
|
||||
}
|
||||
|
||||
func TestRunProxyQualityTarget_AllowedStatusWarnForUnauthorized(t *testing.T) {
|
||||
func TestRunProxyQualityTarget_AllowedStatusPassForUnauthorized(t *testing.T) {
|
||||
server := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, _ *http.Request) {
|
||||
w.WriteHeader(http.StatusUnauthorized)
|
||||
_, _ = w.Write([]byte(`{"error":"unauthorized"}`))
|
||||
@@ -89,7 +89,7 @@ func TestRunProxyQualityTarget_AllowedStatusWarnForUnauthorized(t *testing.T) {
|
||||
}
|
||||
|
||||
item := runProxyQualityTarget(context.Background(), server.Client(), target)
|
||||
require.Equal(t, "warn", item.Status)
|
||||
require.Equal(t, "pass", item.Status)
|
||||
require.Equal(t, http.StatusUnauthorized, item.HTTPStatus)
|
||||
require.Contains(t, item.Message, "目标可达")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user