当前位置:网站首页>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()
边栏推荐
- TensorRT的命令行程序
- CUDA and Direct3D consistency
- CUDA user object
- Latex 编译报错 I found no \bibstyle & \bibdata & \citation command
- Cglib agent - Code enhancement test
- ctf-web之练习赛
- CUDA中的异步数据拷贝
- Tensorrt command line program
- selenium的web自动化中常用的js-修改元素属性翻页
- Idea announced a new default UI, which is too refreshing (including the application link)
猜你喜欢
随机推荐
Log (common log framework)
RestTemplate请求时设置请求头,请求参数,请求体。
MySQL的10大经典错误
查询GPU时无进程运行,但是显存却被占用了
CUDA中的线程层次
Storage space modifier in CUDA
【程序员的自我修养]—找工作反思篇二
提高用户体验 防御性编程
CUDA与Direct3D 一致性
Tensorrt command line program
计算属性普通函数写法 和 set get 写法
FE - Eggjs 结合 Typeorm 出现连接不了数据库
Solution to the black screen of win computer screenshot
利用NVIDIA GPU将Minecraft场景渲染成真实场景
Latex 编译报错 I found no \bibstyle & \bibdata & \citation command
TensorRT的命令行程序
Codeforces Round #797 (Div. 3) A—E
Function execution space specifier in CUDA
一口气说出 6 种实现延时消息的方案
底层机制Mvcc








![Data science [viii]: SVD (I)](/img/cb/7bf066a656d49666985a865c3a1456.png)