whistle.pastekitlab 1.7.6 → 1.7.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/index.js +39 -17
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -162,14 +162,23 @@ async function forwardRequest(req, res, url) {
|
|
|
162
162
|
|
|
163
163
|
// 转换响应数据
|
|
164
164
|
let responseBody;
|
|
165
|
-
if (
|
|
165
|
+
if (Buffer.isBuffer(response.data)) {
|
|
166
166
|
responseBody = response.data;
|
|
167
|
-
} else if (
|
|
167
|
+
} else if (typeof response.data === 'string') {
|
|
168
168
|
responseBody = response.data;
|
|
169
169
|
} else if (typeof response.data === 'object') {
|
|
170
|
-
|
|
170
|
+
try {
|
|
171
|
+
responseBody = JSON.stringify(response.data);
|
|
172
|
+
} catch (e) {
|
|
173
|
+
responseBody = String(response.data);
|
|
174
|
+
}
|
|
171
175
|
} else {
|
|
172
|
-
responseBody = String(response.data);
|
|
176
|
+
responseBody = String(response.data || '');
|
|
177
|
+
}
|
|
178
|
+
|
|
179
|
+
// 确保 responseBody 是有效的字符串或 Buffer
|
|
180
|
+
if (typeof responseBody !== 'string' && !Buffer.isBuffer(responseBody)) {
|
|
181
|
+
responseBody = String(responseBody || '');
|
|
173
182
|
}
|
|
174
183
|
|
|
175
184
|
res.end(responseBody);
|
|
@@ -239,14 +248,33 @@ module.exports = (server, options) => {
|
|
|
239
248
|
|
|
240
249
|
// 转换响应数据为 Buffer 或字符串
|
|
241
250
|
let responseBody;
|
|
242
|
-
|
|
251
|
+
let responseBodyForNotification = null;
|
|
252
|
+
|
|
253
|
+
if (Buffer.isBuffer(response.data)) {
|
|
243
254
|
responseBody = response.data;
|
|
244
|
-
|
|
255
|
+
responseBodyForNotification = bufferToString(response.data);
|
|
256
|
+
} else if (typeof response.data === 'string') {
|
|
245
257
|
responseBody = response.data;
|
|
258
|
+
responseBodyForNotification = response.data;
|
|
246
259
|
} else if (typeof response.data === 'object') {
|
|
247
|
-
|
|
260
|
+
try {
|
|
261
|
+
const jsonStr = JSON.stringify(response.data);
|
|
262
|
+
responseBody = jsonStr;
|
|
263
|
+
responseBodyForNotification = jsonStr;
|
|
264
|
+
} catch (e) {
|
|
265
|
+
const str = String(response.data);
|
|
266
|
+
responseBody = str;
|
|
267
|
+
responseBodyForNotification = str;
|
|
268
|
+
}
|
|
248
269
|
} else {
|
|
249
|
-
|
|
270
|
+
const str = String(response.data || '');
|
|
271
|
+
responseBody = str;
|
|
272
|
+
responseBodyForNotification = str;
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
// 确保 responseBody 是有效的字符串或 Buffer
|
|
276
|
+
if (typeof responseBody !== 'string' && !Buffer.isBuffer(responseBody)) {
|
|
277
|
+
responseBody = String(responseBody || '');
|
|
250
278
|
}
|
|
251
279
|
|
|
252
280
|
// 返回响应体
|
|
@@ -257,15 +285,9 @@ module.exports = (server, options) => {
|
|
|
257
285
|
...requestData,
|
|
258
286
|
statusCode: response.status,
|
|
259
287
|
responseHeaders: {...response.headers},
|
|
260
|
-
responseBody:
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
: Buffer.from(JSON.stringify(response.data))
|
|
264
|
-
),
|
|
265
|
-
responseBodyBase64: (
|
|
266
|
-
typeof response.data === 'string'
|
|
267
|
-
? Buffer.from(response.data)
|
|
268
|
-
: Buffer.from(JSON.stringify(response.data))
|
|
288
|
+
responseBody: responseBodyForNotification,
|
|
289
|
+
responseBodyBase64: Buffer.from(
|
|
290
|
+
typeof responseBody === 'string' ? responseBody : responseBody.toString()
|
|
269
291
|
).toString('base64'),
|
|
270
292
|
duration
|
|
271
293
|
};
|
package/package.json
CHANGED