Apply suggestions from code review

Co-authored-by: anatawa12 <anatawa12@icloud.com>
This commit is contained in:
rectcoordsystem 2024-11-13 03:06:22 +09:00 committed by Julia Johannesen
parent 7ccccf5545
commit 663c06be00
No known key found for this signature in database
GPG key ID: 4A1377AF3E7FBC46

View file

@ -26,21 +26,24 @@ export type HttpRequestSendOptions = {
validators?: ((res: Response) => void)[];
};
@Injectable()
declare module 'node:http' {
interface Agent {
createConnection(options: net.NetConnectOpts, callback?: (err: unknown, stream: net.Socket) => void): net.Socket;
}
}
class HttpRequestServiceAgent extends http.Agent {
constructor(
@Inject(DI.config)
private config: Config,
options?: Object
options?: http.AgentOptions,
) {
super(options);
}
@bindThis
public createConnection(options: Object, callback?: Function): net.Socket {
public createConnection(options: net.NetConnectOpts, callback?: (err: unknown, stream: net.Socket) => void): net.Socket {
const socket = super.createConnection(options, callback)
.on('connect', ()=>{
.on('connect', () => {
const address = socket.remoteAddress;
if (process.env.NODE_ENV === 'production') {
if (address && ipaddr.isValid(address)) {
@ -68,13 +71,10 @@ class HttpRequestServiceAgent extends http.Agent {
}
}
@Injectable()
class HttpsRequestServiceAgent extends https.Agent {
constructor(
@Inject(DI.config)
private config: Config,
options?: Object
options?: https.AgentOptions,
) {
super(options);
}