From: Justin Wind Date: Fri, 7 Jun 2024 22:30:18 +0000 (-0700) Subject: loft named regexps to file level X-Git-Tag: v2.1.2^2~2 X-Git-Url: https://git.squeep.com/?a=commitdiff_plain;h=0ecd0d3e356bdac20294a31e50a8be6e2924adc2;p=squeep-api-dingus loft named regexps to file level --- 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);