From 0ecd0d3e356bdac20294a31e50a8be6e2924adc2 Mon Sep 17 00:00:00 2001 From: Justin Wind Date: Fri, 7 Jun 2024 15:30:18 -0700 Subject: [PATCH] loft named regexps to file level --- lib/dingus.js | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/lib/dingus.js b/lib/dingus.js index 1bda0c2..c53e469 100644 --- a/lib/dingus.js +++ b/lib/dingus.js @@ -38,7 +38,10 @@ const defaultOptions = { querystring, }; -const cookieSplitRE = /; */; +const cookieSplitRE = /\s*;\s*/; +const headerParseRE = /^(?[^:]+): +(?.*)$/; +const lineBreakRE = /\r\n|\n|\r/; +const proxySplitRE = /\s*,\s*/u; class Dingus { /** @@ -161,7 +164,7 @@ class Dingus { (this.trustProxy && req?.getHeader(Enum.Header.XRealIP)) || (req?.connection?.remoteAddress) || ''; - return address.split(/\s*,\s*/u)[0]; + return address.split(proxySplitRE)[0]; } @@ -174,7 +177,7 @@ class Dingus { // TODO: RFC7239 Forwarded support const protocol = (this.trustProxy && req?.getHeader(Enum.Header.XForwardedProto)) || ((req?.connection?.encrypted) ? 'https' : 'http'); - return protocol.split(/\s*,\s*/u)[0]; + return protocol.split(proxySplitRE)[0]; } @@ -582,11 +585,9 @@ class Dingus { return added; } - const lineBreakRE = /\r\n|\n|\r/; const lines = data.toString().split(lineBreakRE); common.unfoldHeaderLines(lines); - const headerParseRE = /^(?[^:]+): +(?.*)$/; lines.forEach((line) => { if (line) { const result = headerParseRE.exec(line); -- 2.44.2