1
0

feat: HTTP 探针增强 — ignoreSSL、精确重定向控制、状态码范围匹配、编码自动检测

This commit is contained in:
2026-05-13 00:02:04 +08:00
parent 87d946a441
commit 2fd0f206be
16 changed files with 642 additions and 22 deletions

View File

@@ -95,7 +95,9 @@ describe("loadConfig", () => {
expect(t.http.url).toBe("http://example.com");
expect(t.http.method).toBe("GET");
expect(t.http.headers).toEqual({});
expect(t.http.ignoreSSL).toBe(false);
expect(t.http.maxBodyBytes).toBe(104857600);
expect(t.http.maxRedirects).toBe(0);
expect(t.intervalMs).toBe(30000);
expect(t.timeoutMs).toBe(10000);
}
@@ -157,8 +159,10 @@ targets:
interval: "1m"
http:
url: "http://example.com"
ignoreSSL: true
maxRedirects: 5
expect:
status: [200]
status: ["2xx", 301]
body:
- contains: "ok"
- name: "cmd-target"
@@ -184,7 +188,10 @@ targets:
expect(http.http.url).toBe("http://example.com");
expect(http.http.method).toBe("POST");
expect(http.http.headers).toEqual({ Authorization: "Bearer token" });
expect(http.http.ignoreSSL).toBe(true);
expect(http.http.maxBodyBytes).toBe(52428800);
expect(http.http.maxRedirects).toBe(5);
expect(http.expect?.status).toEqual(["2xx", 301]);
expect(http.intervalMs).toBe(60000);
expect(http.timeoutMs).toBe(5000);
}
@@ -277,6 +284,68 @@ targets:
await expect(loadConfig(configPath)).rejects.toThrow("缺少 http.url 字段");
});
test("HTTP target 缺少 http 分组抛出清晰错误", async () => {
const configPath = join(tempDir, "no-http-group.yaml");
await writeFile(
configPath,
`targets:
- name: "test"
type: http
`,
);
// eslint-disable-next-line @typescript-eslint/await-thenable
await expect(loadConfig(configPath)).rejects.toThrow("缺少 http.url 字段");
});
test("HTTP target ignoreSSL 非布尔值抛出错误", async () => {
const configPath = join(tempDir, "bad-ignore-ssl.yaml");
await writeFile(
configPath,
`targets:
- name: "test"
type: http
http:
url: "http://example.com"
ignoreSSL: "true"
`,
);
// eslint-disable-next-line @typescript-eslint/await-thenable
await expect(loadConfig(configPath)).rejects.toThrow("ignoreSSL 必须为布尔值");
});
test("HTTP target maxRedirects 非负整数校验", async () => {
const configPath = join(tempDir, "bad-max-redirects.yaml");
await writeFile(
configPath,
`targets:
- name: "test"
type: http
http:
url: "http://example.com"
maxRedirects: 1.5
`,
);
// eslint-disable-next-line @typescript-eslint/await-thenable
await expect(loadConfig(configPath)).rejects.toThrow("maxRedirects 必须为非负整数");
});
test("HTTP target status 模式非法抛出错误", async () => {
const configPath = join(tempDir, "bad-status-pattern.yaml");
await writeFile(
configPath,
`targets:
- name: "test"
type: http
http:
url: "http://example.com"
expect:
status: ["abc"]
`,
);
// eslint-disable-next-line @typescript-eslint/await-thenable
await expect(loadConfig(configPath)).rejects.toThrow("status 模式");
});
test("command target 缺少 exec 抛出错误", async () => {
const configPath = join(tempDir, "no-exec.yaml");
await writeFile(