node-digest-auth
Advanced tools
@@ -9,4 +9,8 @@ /// <reference types="node" /> | ||
| private httpRequest; | ||
| private authenticatedSocket; | ||
| constructor(username: string, password: string, useHttps?: boolean, shouldEnd?: boolean); | ||
| request(options: http.RequestOptions, callback: (res: http.IncomingMessage) => void): http.ClientRequest; | ||
| request(options: http.RequestOptions, callback: (res: http.IncomingMessage) => void): { | ||
| request: http.ClientRequest; | ||
| getSocket: () => any; | ||
| }; | ||
| private _handleResponse; | ||
@@ -13,0 +17,0 @@ private _parseChallenge; |
+24
-14
@@ -32,2 +32,3 @@ "use strict"; | ||
| constructor(username, password, useHttps = false, shouldEnd = false) { | ||
| this.authenticatedSocket = null; // Add this line | ||
| this.nc = 0; | ||
@@ -40,14 +41,20 @@ this.username = username; | ||
| request(options, callback) { | ||
| // Create the request but don't end it immediately | ||
| const req = this.httpRequest.request(options, (res) => { | ||
| this._handleResponse(options, res, callback); | ||
| }); | ||
| // Listen for the socket event to capture the underlying socket | ||
| let initialSocket = null; | ||
| req.on("socket", (sock) => { | ||
| initialSocket = sock; | ||
| }); | ||
| // If shouldEnd is true, end the request | ||
| if (this.shouldEnd) { | ||
| return this.httpRequest | ||
| .request(options, (res) => { | ||
| this._handleResponse(options, res, callback); | ||
| }) | ||
| .end(); | ||
| req.end(); | ||
| } | ||
| else { | ||
| return this.httpRequest.request(options, (res) => { | ||
| this._handleResponse(options, res, callback); | ||
| }); | ||
| } | ||
| // Return the request and the captured socket | ||
| return { | ||
| request: req, | ||
| getSocket: () => this.authenticatedSocket || initialSocket, // Prefer the authenticated socket if available | ||
| }; | ||
| } | ||
@@ -91,8 +98,11 @@ _handleResponse(options, res, callback) { | ||
| options.headers = Object.assign(Object.assign({}, options.headers), { Authorization: this._compileParams(authParams) }); | ||
| const req = http.request(options, callback); | ||
| // Capture the authenticated socket | ||
| req.on("socket", (sock) => { | ||
| this.authenticatedSocket = sock; | ||
| }); | ||
| if (this.shouldEnd) { | ||
| return http.request(options, callback).end(); | ||
| req.end(); | ||
| } | ||
| else { | ||
| return http.request(options, callback); | ||
| } | ||
| return req; | ||
| } | ||
@@ -99,0 +109,0 @@ _parseChallenge(digest) { |
+1
-1
| { | ||
| "name": "node-digest-auth", | ||
| "version": "1.0.3", | ||
| "version": "1.0.4", | ||
| "description": "Digest Auth Package", | ||
@@ -5,0 +5,0 @@ "main": "dist/digestClient.js", |
14108
4.29%330
4.43%