Harden connectivity probe, add checking state, support URLTest/Fallback groups, MIT license

This commit is contained in:
av
2026-07-18 16:29:20 +03:00
parent fc83c57382
commit ec673b92f3
5 changed files with 207 additions and 106 deletions
+12 -2
View File
@@ -16,7 +16,9 @@ const textEncoder = new TextEncoder();
export class ClashApi {
constructor({ url = 'http://127.0.0.1:9090', secret = '' } = {}) {
this._session = new Soup.Session();
this._session.timeout = 5;
// Above the 5 s /delay probe budget so libsoup's inactivity timeout
// doesn't abort a slow-but-alive latency measurement client-side.
this._session.timeout = 10;
this.setEndpoint(url, secret);
}
@@ -25,8 +27,16 @@ export class ClashApi {
this._secret = secret || '';
}
// Abort all in-flight requests and drop idle keep-alive connections.
destroy() {
this._session.abort();
}
_message(method, path, body) {
const msg = Soup.Message.new(method, `${this._baseUrl}${path}`);
const uri = `${this._baseUrl}${path}`;
const msg = Soup.Message.new(method, uri);
if (!msg)
throw new Error(`Invalid API URL: ${uri}`);
const headers = msg.get_request_headers();
headers.append('Accept', 'application/json');
if (this._secret)