当前位置:网站首页>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()
边栏推荐
- Redis——缓存击穿、穿透、雪崩
- CUDA中的Warp Shuffle
- Thread hierarchy in CUDA
- 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)
- Selenium memo: selenium\webdriver\remote\remote_ connection. Py:374: resourcewarning: unclosed < XXXX > solution
- Asynchronous data copy in CUDA
- 构建学习tensorflow
- Fe - use of weex development weex UI components and configuration use
- Redis - big key problem
- CUDA中内置的Vector类型和变量
猜你喜欢

20201002 vs 2019 qt5.14 developed program packaging

Introduce two automatic code generators to help improve work efficiency

实现strStr() II

Latest CUDA environment configuration (win10 + CUDA 11.6 + vs2019)

Win电脑截图黑屏解决办法

IDEA公布全新默认UI,太清爽了(内含申请链接)

Win10网络图标消失,网络图标变成灰色,打开网络设置闪退等问题解决

华为MindSpore开源实习机试题

PgSQL学习笔记

实习生跑路留了一个大坑,搞出2个线上问题,我被坑惨了
随机推荐
TensorRT的命令行程序
Sentinel 阿里开源流量防护组件
Tensorrt command line program
Kotlin - verify whether the time format is yyyy MM DD hh:mm:ss
CUDA and Direct3D consistency
kali最新更新指南
计算属性普通函数写法 和 set get 写法
Alibaba cloud MFA binding Chrome browser
ModuleNotFoundError: No module named ‘jieba.analyse‘; ‘jieba‘ is not a package
Golang -- map capacity expansion mechanism (including source code)
Top 10 classic MySQL errors
Win10网络图标消失,网络图标变成灰色,打开网络设置闪退等问题解决
MySql索引
Latex参考文献引用失败 报错 LaTeX Warning: Citation “*****” on page y undefined on input line *
广告业务Bug复盘总结
Sparse array (nonlinear structure)
由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
华为MindSpore开源实习机试题
Cglib agent - Code enhancement test
Unexpected inconsistency caused by abnormal power failure; Run fsck manually problem resolved