当前位置:网站首页>Nodejs - Express middleware modification header: typeerror [err_invalid_char]: invalid character in header content
Nodejs - Express middleware modification header: typeerror [err_invalid_char]: invalid character in header content
2022-07-02 06:38:00 【Xiao Ming Yuan】
background
Use Express The data proxy method of middleware , Unified use of user information Redis cache
- user-redis
const user_redis = async function (req, res, next) {
const token = req.headers['authorization']
const user = await redis.client.getAsync(token).then((data) => {
return data
})
// to header Add user information , The result is abnormal
req.headers.user_info = user
next()
}
Abnormal information
TypeError [ERR_INVALID_CHAR]: Invalid character in header content ["user_info"]
at ClientRequest.setHeader (_http_outgoing.js:473:3)
at new ClientRequest (_http_client.js:193:14)
......
resolvent
Reference resources :
https://github.com/expressjs/express/issues/3401
take user Information goes on base64 After the coding , Decode at the application layer ;
- user_redis
const user_redis = async function (req, res, next) {
const token = req.headers['authorization']
const user = await redis.client.getAsync(token).then((data) => {
return data
})
// to header Add user information , The result is abnormal
req.headers.user_info = Buffer.from(user).toString('base64')
next()
}
- application
const user_str = req.headers.user_info
const userInfo = Buffer.from(user_str,'base64').toString()
边栏推荐
- Three suggestions for all students who have graduated and will graduate
- 由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
- VSCODE 安装LATEX环境,参数配置,常见问题解决
- Render minecraft scenes into real scenes using NVIDIA GPU
- Sentinel rules persist to Nacos
- qq邮箱接收不到jenkins构建后使用email extension 发送的邮件(timestamp 或 auth.......)
- AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组
- Does the assignment of Boolean types such as tag attribute disabled selected checked not take effect?
- Selenium memo: selenium\webdriver\remote\remote_ connection. Py:374: resourcewarning: unclosed < XXXX > solution
- Flask-Migrate 检测不到db.string() 等长度变化
猜你喜欢
![Data science [viii]: SVD (I)](/img/cb/7bf066a656d49666985a865c3a1456.png)
Data science [viii]: SVD (I)

实现strStr() II

Blog directory of zzq -- updated on 20210601

unittest.TextTestRunner不生成txt测试报告

Sentinel rules persist to Nacos

Win10:添加或者删除开机启动项,在开机启动项中添加在用户自定义的启动文件

Summary of WLAN related knowledge points

Learn about various joins in SQL and their differences

阿里云MFA绑定Chrome浏览器

自学table au
随机推荐
奇葩pip install
Thread hierarchy in CUDA
TensorRT中的循环
Redis——Cluster数据分布算法&哈希槽
Latex 报错 LaTeX Error: The font size command \normalsize is not defined问题解决
Golang -- map capacity expansion mechanism (including source code)
NodeJs - Express 中间件修改 Header: TypeError [ERR_INVALID_CHAR]: Invalid character in header content
unittest. Texttestrunner does not generate TXT test reports
Fe - weex uses a simple encapsulated data loading plug-in as the global loading method
pytest(2) mark功能
Fe - use of weex development weex UI components and configuration use
Kotlin - verify whether the time format is yyyy MM DD hh:mm:ss
20210306 reprint how to make TextEdit have background pictures
Uploading attachments using Win32 in Web Automation
Redis---1. Data structure characteristics and operation
Codeforces Round #797 (Div. 3) A—E
eslint配置代码自动格式化
Redis - hot key issues
ctf三计
Warp shuffle in CUDA