Skip to content

Commit

Permalink
feat: return socket from createConnection (#113)
Browse files Browse the repository at this point in the history
As per http.agent [createConnection](https://nodejs.org/api/http.html#agentcreateconnectionoptions-callback) method, the method should return a socket but I found that current implemenation of createConnection for Agent doesn't return socket.

Co-authored-by: Nabeel Bukhari <nabeel.bukhari@zalando.de>
  • Loading branch information
nabeelbukhari and Nabeel Bukhari committed Aug 4, 2023
1 parent 2092714 commit c7c1e93
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 2 deletions.
3 changes: 3 additions & 0 deletions index.d.ts
@@ -1,5 +1,6 @@
import * as http from 'http';
import * as https from 'https';
import * as net from 'net';

interface PlainObject {
[key: string]: any;
Expand All @@ -8,6 +9,7 @@ interface PlainObject {
declare class HttpAgent extends http.Agent {
constructor(opts?: AgentKeepAlive.HttpOptions);
readonly statusChanged: boolean;
createConnection(options: net.NetConnectOpts, cb?: Function): net.Socket;
createSocket(req: http.IncomingMessage, options: http.RequestOptions, cb: Function): void;
getCurrentStatus(): AgentKeepAlive.AgentStatus;
}
Expand Down Expand Up @@ -52,6 +54,7 @@ declare namespace AgentKeepAlive {
export class HttpsAgent extends https.Agent {
constructor(opts?: HttpsOptions);
readonly statusChanged: boolean;
createConnection(options: net.NetConnectOpts, cb?: Function): net.Socket;
createSocket(req: http.IncomingMessage, options: http.RequestOptions, cb: Function): void;
getCurrentStatus(): AgentStatus;
}
Expand Down
1 change: 1 addition & 0 deletions lib/agent.js
Expand Up @@ -230,6 +230,7 @@ class Agent extends OriginalAgent {

const newSocket = super.createConnection(options, onNewCreate);
if (newSocket) onNewCreate(null, newSocket);
return newSocket;
}

get statusChanged() {
Expand Down
4 changes: 2 additions & 2 deletions lib/https_agent.js
Expand Up @@ -25,8 +25,8 @@ class HttpsAgent extends HttpAgent {
};
}

createConnection(options) {
const socket = this[CREATE_HTTPS_CONNECTION](options);
createConnection(options, oncreate) {
const socket = this[CREATE_HTTPS_CONNECTION](options, oncreate);
this[INIT_SOCKET](socket, options);
return socket;
}
Expand Down

0 comments on commit c7c1e93

Please sign in to comment.