actionhero
Version:
The reusable, scalable, and quick node.js API server for stateless and stateful applications
14 lines (13 loc) • 397 B
text/typescript
/**
* Transform the cookie headers of a node HTTP `req` Object into a hash.
*/
export function parseCookies(req: { headers: { [key: string]: any } }): object {
const cookies = {};
if (req.headers.cookie) {
req.headers.cookie.split(";").forEach((cookie) => {
const parts = cookie.split("=");
cookies[parts[0].trim()] = (parts[1] || "").trim();
});
}
return cookies;
}