Skip to content

Commit

Permalink
fix #1732 (#2272)
Browse files Browse the repository at this point in the history
  • Loading branch information
MoritzLoewenstein authored Feb 8, 2023
1 parent bf14c3b commit 6926648
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 26 deletions.
41 changes: 16 additions & 25 deletions lib/winston/transports/http.js
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ module.exports = class Http extends TransportStream {
* @returns {undefined}
*/
log(info, callback) {
this._request(info, (err, res) => {
this._request(info, null, null, (err, res) => {
if (res && res.statusCode !== 200) {
err = new Error(`Invalid HTTP Status Code: ${res.statusCode}`);
}
Expand Down Expand Up @@ -93,17 +93,13 @@ module.exports = class Http extends TransportStream {
params: this.normalizeQuery(options)
};

if (options.params.path) {
options.path = options.params.path;
delete options.params.path;
}
const auth = options.params.auth || null;
delete options.params.auth;

if (options.params.auth) {
options.auth = options.params.auth;
delete options.params.auth;
}
const path = options.params.path || null;
delete options.params.path;

this._request(options, (err, res, body) => {
this._request(options, auth, path, (err, res, body) => {
if (res && res.statusCode !== 200) {
err = new Error(`Invalid HTTP Status Code: ${res.statusCode}`);
}
Expand Down Expand Up @@ -136,18 +132,14 @@ module.exports = class Http extends TransportStream {
params: options
};

if (options.params.path) {
options.path = options.params.path;
delete options.params.path;
}
const path = options.params.path || null;
delete options.params.path;

if (options.params.auth) {
options.auth = options.params.auth;
delete options.params.auth;
}
const auth = options.params.auth || null;
delete options.params.auth;

let buff = '';
const req = this._request(options);
const req = this._request(options, auth, path);

stream.destroy = () => req.destroy();
req.on('data', data => {
Expand All @@ -174,16 +166,15 @@ module.exports = class Http extends TransportStream {
* Make a request to a winstond server or any http server which can
* handle json-rpc.
* @param {function} options - Options to sent the request.
* @param {Object?} auth - authentication options
* @param {string} path - request path
* @param {function} callback - Continuation to respond to when complete.
*/
_request(options, callback) {
_request(options, auth, path, callback) {
options = options || {};

const auth = options.auth || this.auth;
const path = options.path || this.path || '';

delete options.auth;
delete options.path;
auth = auth || this.auth;
path = path || this.path || '';

if (this.batch) {
this._doBatch(options, callback, auth, path);
Expand Down
3 changes: 2 additions & 1 deletion test/unit/winston/transports/http.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,8 @@ describe('Http({ host, port, path })', function () {
const dummyLog = {
level: 'info',
message: 'hello',
meta: {}
meta: {},
path: '/error'
};

afterEach(function (done) {
Expand Down

0 comments on commit 6926648

Please sign in to comment.