Harden connectivity probe, add checking state, support URLTest/Fallback groups, MIT license
This commit is contained in:
+12
-2
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user