reject all non TLSv1.2 AP queries
Some checks failed
Publish Docker image / Build (push) Waiting to run
Lint / pnpm_install (push) Waiting to run
Lint / lint (backend) (push) Blocked by required conditions
Lint / lint (frontend) (push) Blocked by required conditions
Lint / lint (frontend-embed) (push) Blocked by required conditions
Lint / lint (frontend-shared) (push) Blocked by required conditions
Lint / lint (misskey-bubble-game) (push) Blocked by required conditions
Lint / lint (misskey-js) (push) Blocked by required conditions
Lint / lint (misskey-reversi) (push) Blocked by required conditions
Lint / lint (sw) (push) Blocked by required conditions
Lint / typecheck (backend) (push) Blocked by required conditions
Lint / typecheck (misskey-js) (push) Blocked by required conditions
Lint / typecheck (sw) (push) Blocked by required conditions
Test (backend) / unit (22.11.0) (push) Waiting to run
Test (backend) / e2e (22.11.0) (push) Waiting to run
Test (production install and build) / production (22.11.0) (push) Waiting to run
Lint / pnpm_install (pull_request) Successful in 1m16s
Publish Docker image / Build (pull_request) Successful in 3m50s
Test (production install and build) / production (22.11.0) (pull_request) Successful in 55s
Test (backend) / unit (22.11.0) (pull_request) Failing after 6m38s
Test (backend) / e2e (22.11.0) (pull_request) Failing after 10m0s
Lint / lint (backend) (pull_request) Successful in 2m5s
Lint / lint (frontend) (pull_request) Successful in 2m0s
Lint / lint (frontend-embed) (pull_request) Successful in 1m55s
Lint / lint (frontend-shared) (pull_request) Successful in 1m55s
Lint / lint (misskey-bubble-game) (pull_request) Successful in 2m1s
Lint / lint (misskey-js) (pull_request) Successful in 2m3s
Lint / lint (misskey-reversi) (pull_request) Successful in 2m3s
Lint / typecheck (backend) (pull_request) Failing after 1m24s
Lint / lint (sw) (pull_request) Successful in 2m8s
Lint / typecheck (misskey-js) (pull_request) Successful in 1m24s
Lint / typecheck (sw) (pull_request) Successful in 1m22s

Signed-off-by: eternal-flame-AD <yume@yumechi.jp>
This commit is contained in:
ゆめ 2024-11-21 03:12:47 -06:00
parent 9b8d02d1c3
commit 5b6e8cc110
No known key found for this signature in database

View file

@ -27,21 +27,11 @@ export type HttpRequestSendOptions = {
@Injectable()
export class HttpRequestService {
/**
* Get http non-proxy agent
*/
private http: http.Agent;
/**
* Get https non-proxy agent
*/
private https: https.Agent;
/**
* Get http proxy or non-proxy agent
*/
public httpAgent: http.Agent;
/**
* Get https proxy or non-proxy agent
*/
@ -57,34 +47,16 @@ export class HttpRequestService {
lookup: false, // nativeのdns.lookupにfallbackしない
});
this.http = new http.Agent({
keepAlive: true,
keepAliveMsecs: 30 * 1000,
lookup: cache.lookup as unknown as net.LookupFunction,
localAddress: config.outgoingAddress,
});
this.https = new https.Agent({
keepAlive: true,
keepAliveMsecs: 30 * 1000,
lookup: cache.lookup as unknown as net.LookupFunction,
localAddress: config.outgoingAddress,
minVersion: 'TLSv1.2',
});
const maxSockets = Math.max(256, config.deliverJobConcurrency ?? 128);
this.httpAgent = config.proxy
? new HttpProxyAgent({
keepAlive: true,
keepAliveMsecs: 30 * 1000,
maxSockets,
maxFreeSockets: 256,
scheduling: 'lifo',
proxy: config.proxy,
localAddress: config.outgoingAddress,
})
: this.http;
this.httpsAgent = config.proxy
? new HttpsProxyAgent({
keepAlive: true,
@ -104,11 +76,17 @@ export class HttpRequestService {
* @param bypassProxy Allways bypass proxy
*/
@bindThis
public getAgentByUrl(url: URL, bypassProxy = false): http.Agent | https.Agent {
public getAgentByUrl(url: URL, bypassProxy = false): https.Agent {
if (url.protocol !== 'https:') {
throw new Error('Invalid protocol');
}
if (url.port && url.port !== '443') {
throw new Error('Invalid port');
}
if (bypassProxy || (this.config.proxyBypassHosts ?? []).includes(url.hostname)) {
return url.protocol === 'http:' ? this.http : this.https;
return this.https;
} else {
return url.protocol === 'http:' ? this.httpAgent : this.httpsAgent;
return this.httpsAgent;
}
}