当前位置:网站首页>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()
边栏推荐
- Vector types and variables built in CUDA
- 自学table au
- Redis——大Key問題
- Codeforces Round #797 (Div. 3) A—E
- 查询GPU时无进程运行,但是显存却被占用了
- Three suggestions for all students who have graduated and will graduate
- PgSQL学习笔记
- There is no way to drag the win10 desktop icon (you can select it, open it, delete it, create it, etc., but you can't drag it)
- Latest CUDA environment configuration (win10 + CUDA 11.6 + vs2019)
- CUDA与Direct3D 一致性
猜你喜欢
Learn about various joins in SQL and their differences
Sparse array (nonlinear structure)
Linked list (linear structure)
Présence d'une panne de courant anormale; Problème de gestion de la fsck d'exécution résolu
Redis——Cluster数据分布算法&哈希槽
查询GPU时无进程运行,但是显存却被占用了
实习生跑路留了一个大坑,搞出2个线上问题,我被坑惨了
Distributed transactions: the final consistency scheme of reliable messages
Cglib agent - Code enhancement test
Redis——缓存击穿、穿透、雪崩
随机推荐
由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
Loops in tensorrt
CUDA中的存储空间修饰符
查询GPU时无进程运行,但是显存却被占用了
unittest. Texttestrunner does not generate TXT test reports
QQ email cannot receive the email sent by Jenkins using email extension after construction (timestamp or auth...)
Pytest (2) mark function
eslint配置代码自动格式化
Sublime Text 配置php编译环境
Redis - cluster data distribution algorithm & hash slot
Redis——缓存击穿、穿透、雪崩
Data science [9]: SVD (2)
奇葩pip install
Pytest (3) parameterize
20210306 reprint how to make TextEdit have background pictures
Data science [viii]: SVD (I)
AtCoder Beginner Contest 253 F - Operations on a Matrix // 树状数组
Hydration failed because the initial UI does not match what was rendered on the server. One of the reasons for the problem
代码技巧——Controller参数注解@RequestParam
TensorRT中的循环