当前位置:网站首页>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()
边栏推荐
猜你喜欢
Log (common log framework)
[literature reading and thought notes 13] unprocessing images for learned raw denoising
默认google浏览器打不开链接(点击超链接没有反应)
Idea announced a new default UI, which is too refreshing (including the application link)
Cglib agent - Code enhancement test
Uploading attachments using Win32 in Web Automation
Solution to the black screen of win computer screenshot
Redis——缓存击穿、穿透、雪崩
由於不正常斷電導致的unexpected inconsistency;RUN fsck MANUALLY問題已解决
CUDA中的线程层次
随机推荐
ModuleNotFoundError: No module named ‘jieba.analyse‘; ‘jieba‘ is not a package
广告业务Bug复盘总结
ShardingSphere-JDBC篇
CUDA中的线程层次
Latest CUDA environment configuration (win10 + CUDA 11.6 + vs2019)
Introduce two automatic code generators to help improve work efficiency
Sublime Text 配置php编译环境
CUDA中内置的Vector类型和变量
【每日一题】写一个函数,判断一个字符串是否为另外一个字符串旋转之后的字符串。
Distributed transactions: the final consistency scheme of reliable messages
Warp shuffle in CUDA
代码技巧——Controller参数注解@RequestParam
MySQL的10大經典錯誤
【张三学C语言之】—深入理解数据存储
Virtualenv and pipenv installation
web自动化切换窗口时报错“list“ object is not callable
日志 - 7 - 记录一次丢失文件(A4纸)的重大失误
ctf-web之练习赛
sprintf_s的使用方法
Cglib agent - Code enhancement test