Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix #1732 #2272

Merged
merged 1 commit into from
Feb 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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