querystring,
};
+const cookieSplitRE = /; */;
+
class Dingus {
/**
* @param {Object} logger object which implements logging methods
/**
- * Called before every request handler.
- * Sets tracking identifiers and client information on ctx.
+ * Sets ctx.cookie from Cookie header.
* @param {http.ClientRequest} req
* @param {http.ServerResponse} res
* @param {object} ctx
*/
+ 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) {
+ 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
+ }
+ });
+ }
+
+
+ /**
+ * Called before every request handler.
+ * Sets tracking identifiers and client information on ctx.
+ * @param {http.ClientRequest} req
+ * @param {http.ServerResponse} res
+ * @param {object} ctx
+ */
async preHandler(req, res, ctx) {
- Dingus.tagContext(req, res, ctx);
+ this.constructor.tagContext(req, res, ctx);
this.clientAddressContext(req, res, ctx);
+ this.constructor.ingestCookie(req, res, ctx);
}