UNPKG

hono-sess

Version:

A Simple Session Middleware for Hono

48 lines 1.67 kB
'use strict'; import crypto from 'crypto'; import dbg from 'debug'; import depd from 'depd'; export const debug = dbg('hono-sess'); export const deprecate = depd('hono-sess'); export const warning = 'Warning: connect.session() MemoryStore is not\n' + 'designed for a production environment, as it will leak\n' + 'memory, and will not scale past a single process.'; export function hash(session) { var str = JSON.stringify(session, function (key, val) { if (this === session && key === 'cookie') { return; } return val; }); return crypto.createHash('sha1').update(str, 'utf8').digest('hex'); } export function issecure(req, trustProxy) { if (req.url.startsWith('https://') || req.url.startsWith('wss://')) { return true; } if (trustProxy === false) { return false; } var header = req.header('x-forwarded-proto') || ''; var index = header.indexOf(','); var proto = index !== -1 ? header.substring(0, index).toLowerCase().trim() : header.toLowerCase().trim(); return proto === 'https'; } export function expressCookieOptionsToHonoCookieOptions(options, req, proxy) { const { priority, ...rest } = options; return { ...rest, sameSite: options.sameSite === true ? 'strict' : options.sameSite === false ? 'lax' : options.sameSite === 'none' ? 'none' : undefined, expires: options.expires || undefined, secure: options.secure === 'auto' ? issecure(req, proxy) : options.secure, }; } //# sourceMappingURL=utils.js.map