whistle.pastekitlab 1.7.8 → 1.8.0
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 +10 -3
- package/package.json +1 -1
package/index.js
CHANGED
|
@@ -40,13 +40,20 @@ function bufferToString(buffer) {
|
|
|
40
40
|
try {
|
|
41
41
|
if (!buffer) return null;
|
|
42
42
|
const result = buffer.toString('utf8');
|
|
43
|
-
if (/[
|
|
43
|
+
if (/[\uFFFD]/.test(result)) return null; // 检查是否有替换字符
|
|
44
44
|
return result;
|
|
45
45
|
} catch {
|
|
46
46
|
return null;
|
|
47
47
|
}
|
|
48
48
|
}
|
|
49
49
|
|
|
50
|
+
// 限制字符串长度,避免 WebSocket 消息过大
|
|
51
|
+
function truncateString(str, maxLength = 1024 * 1024) { // 默认 1MB
|
|
52
|
+
if (!str) return str;
|
|
53
|
+
if (str.length <= maxLength) return str;
|
|
54
|
+
return str.substring(0, maxLength) + '\n... [truncated]';
|
|
55
|
+
}
|
|
56
|
+
|
|
50
57
|
function bufferToBase64(buffer) {
|
|
51
58
|
try {
|
|
52
59
|
return buffer ? buffer.toString('base64') : null;
|
|
@@ -220,7 +227,7 @@ module.exports = (server, options) => {
|
|
|
220
227
|
url,
|
|
221
228
|
method: req.method,
|
|
222
229
|
requestHeaders: {...req.headers},
|
|
223
|
-
body: bufferToString(Buffer.from(reqBody)),
|
|
230
|
+
body: truncateString(bufferToString(Buffer.from(reqBody))),
|
|
224
231
|
bodyBase64: Buffer.from(reqBody).toString('base64'),
|
|
225
232
|
timestamp: Date.now()
|
|
226
233
|
};
|
|
@@ -285,7 +292,7 @@ module.exports = (server, options) => {
|
|
|
285
292
|
...requestData,
|
|
286
293
|
statusCode: response.status,
|
|
287
294
|
responseHeaders: {...response.headers},
|
|
288
|
-
responseBody: responseBodyForNotification,
|
|
295
|
+
responseBody: truncateString(responseBodyForNotification),
|
|
289
296
|
responseBodyBase64: Buffer.from(
|
|
290
297
|
typeof responseBody === 'string' ? responseBody : responseBody.toString()
|
|
291
298
|
).toString('base64'),
|
package/package.json
CHANGED