Skip to content

Commit 6926648

Browse files
fix #1732 (#2272)
1 parent bf14c3b commit 6926648

File tree

2 files changed

+18
-26
lines changed

2 files changed

+18
-26
lines changed

lib/winston/transports/http.js

+16-25
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@ module.exports = class Http extends TransportStream {
5757
* @returns {undefined}
5858
*/
5959
log(info, callback) {
60-
this._request(info, (err, res) => {
60+
this._request(info, null, null, (err, res) => {
6161
if (res && res.statusCode !== 200) {
6262
err = new Error(`Invalid HTTP Status Code: ${res.statusCode}`);
6363
}
@@ -93,17 +93,13 @@ module.exports = class Http extends TransportStream {
9393
params: this.normalizeQuery(options)
9494
};
9595

96-
if (options.params.path) {
97-
options.path = options.params.path;
98-
delete options.params.path;
99-
}
96+
const auth = options.params.auth || null;
97+
delete options.params.auth;
10098

101-
if (options.params.auth) {
102-
options.auth = options.params.auth;
103-
delete options.params.auth;
104-
}
99+
const path = options.params.path || null;
100+
delete options.params.path;
105101

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

139-
if (options.params.path) {
140-
options.path = options.params.path;
141-
delete options.params.path;
142-
}
135+
const path = options.params.path || null;
136+
delete options.params.path;
143137

144-
if (options.params.auth) {
145-
options.auth = options.params.auth;
146-
delete options.params.auth;
147-
}
138+
const auth = options.params.auth || null;
139+
delete options.params.auth;
148140

149141
let buff = '';
150-
const req = this._request(options);
142+
const req = this._request(options, auth, path);
151143

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

182-
const auth = options.auth || this.auth;
183-
const path = options.path || this.path || '';
184-
185-
delete options.auth;
186-
delete options.path;
176+
auth = auth || this.auth;
177+
path = path || this.path || '';
187178

188179
if (this.batch) {
189180
this._doBatch(options, callback, auth, path);

test/unit/winston/transports/http.test.js

+2-1
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ describe('Http({ host, port, path })', function () {
5151
const dummyLog = {
5252
level: 'info',
5353
message: 'hello',
54-
meta: {}
54+
meta: {},
55+
path: '/error'
5556
};
5657

5758
afterEach(function (done) {

0 commit comments

Comments
 (0)