diff options
Diffstat (limited to 'api/headers.js')
| -rw-r--r-- | api/headers.js | 25 |
1 files changed, 17 insertions, 8 deletions
diff --git a/api/headers.js b/api/headers.js index 9cbf6ac3..73d00231 100644 --- a/api/headers.js +++ b/api/headers.js @@ -1,13 +1,22 @@ -// headers.js export default (req, res) => { - const headers = res.headers(); + // 获取所有当前设置的响应头 + const headers = res.getHeaders(); + + // 遍历响应头,修正非 ASCII 字符 for (const key in headers) { const value = headers[key]; - if (typeof value === 'string') { - headers[key] = value.replace(/[^\x00-\x7F]/g, (char) => { - return `%${char.charCodeAt(0).toString(16).toUpperCase()}`; - }); + if (typeof value === "string") { + // 将非 ASCII 字符进行百分比编码 + const encodedValue = value.replace(/[^\x00-\x7F]/g, (char) => + `%${char.charCodeAt(0).toString(16).toUpperCase()}` + ); + + // 重置响应头 + res.setHeader(key, encodedValue); } } - return res; - };
\ No newline at end of file + + // 返回响应 + res.status(200).send("Headers processed successfully."); + }; +
\ No newline at end of file |
