UNPKG

titbit-toolkit

Version:

titbit框架的工具集,包括跨域、静态资源处理,权限过滤,请求计时,cookie,session,jwt等大量中间件

47 lines (31 loc) 787 B
'use strict'; class Cookie { constructor() { } mid() { return async (rr, next) => { rr.cookie = {}; if (rr.headers['cookie']) { let cookies = rr.headers['cookie'].split(';').filter(c => c.length > 0); let tmpList = []; let name = ''; for(let i = 0; i < cookies.length; i++) { tmpList = cookies[i].split('=').filter(p => p.length > 0); name = tmpList[0].trim(); if (name.length == 0) { continue; } if (tmpList.length < 2) { rr.cookie[name] = ''; } else { rr.cookie[name] = tmpList[1]; } } } await next(); rr.cookie = null; }; } } module.exports = Cookie;