@less-is-more/less-js 1.4.34-0 → 1.4.34-1
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/package.json +1 -1
- package/src/router.js +33 -31
package/package.json
CHANGED
package/src/router.js
CHANGED
|
@@ -199,43 +199,45 @@ module.exports = class Router {
|
|
|
199
199
|
|
|
200
200
|
static _handleReturn(result, startTime, req, res) {
|
|
201
201
|
const useTime = (new Date().getTime() - startTime) / 1000;
|
|
202
|
-
if (
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
if (
|
|
202
|
+
if (Buffer.isBuffer(result)) {
|
|
203
|
+
res.send(result);
|
|
204
|
+
} else {
|
|
205
|
+
if (!Param.isBlank(result)) {
|
|
206
|
+
let content;
|
|
207
|
+
if (result instanceof Ret) {
|
|
208
208
|
content = result.toString();
|
|
209
|
-
} else if (typeof result === "string") {
|
|
210
|
-
content = result;
|
|
211
209
|
} else {
|
|
212
|
-
|
|
210
|
+
if (typeof result === "string") {
|
|
211
|
+
content = result;
|
|
212
|
+
} else {
|
|
213
|
+
content = JSON.stringify(result);
|
|
214
|
+
}
|
|
213
215
|
}
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
216
|
+
console.log(
|
|
217
|
+
useTime + "s",
|
|
218
|
+
req.path,
|
|
219
|
+
"response:",
|
|
220
|
+
content.substring(0, 500)
|
|
221
|
+
);
|
|
222
|
+
// 处理header带压缩支持的情况
|
|
223
|
+
if (req.headers) {
|
|
224
|
+
const acceptEncoding =
|
|
225
|
+
req.headers["Accept-Encoding"] || req.headers["accept-encoding"];
|
|
226
|
+
if (acceptEncoding) {
|
|
227
|
+
if (acceptEncoding.includes("br")) {
|
|
228
|
+
content = zlib.brotliCompressSync(content);
|
|
229
|
+
res.setHeader("Content-Encoding", "br");
|
|
230
|
+
} else if (acceptEncoding.includes("gzip")) {
|
|
231
|
+
content = zlib.gzipSync(content);
|
|
232
|
+
res.setHeader("Content-Encoding", "gzip");
|
|
233
|
+
} else if (acceptEncoding.includes("deflate")) {
|
|
234
|
+
content = zlib.deflateSync(content);
|
|
235
|
+
res.setHeader("Content-Encoding", "deflate");
|
|
236
|
+
}
|
|
235
237
|
}
|
|
236
238
|
}
|
|
239
|
+
res.send(content);
|
|
237
240
|
}
|
|
238
|
-
res.send(content);
|
|
239
241
|
}
|
|
240
242
|
}
|
|
241
243
|
|