+ /**
+ * Sets ctx.cookie from Cookie header.
+ * @param {http.ClientRequest} req request
+ * @param {http.ServerResponse} res response
+ * @param {object} ctx context
+ */
+ static ingestCookie(req, res, ctx) {
+ ctx.cookie = {};
+ req.getHeader(Enum.Header.Cookie)?.split(cookieSplitRE).forEach((cookie) => {
+ const [ name, value ] = common.splitFirst(cookie, '=', null).map((x) => {
+ try {
+ return decodeURIComponent(x.trim());
+ } catch (e) { // eslint-disable-line no-unused-vars
+ return x;
+ }
+ });
+ if (name && !(name in ctx.cookie)) {
+ const isQuoted = value?.startsWith('"') && value.endsWith('"');
+ ctx.cookie[name] = isQuoted ? value.slice(1, -1) : value; // eslint-disable-line security/detect-object-injection
+ }
+ });
+ }
+
+