@edge-runtime/cookies
Advanced tools
Comparing version 3.0.2 to 3.0.3
@@ -160,9 +160,10 @@ "use strict"; | ||
this._parsed = /* @__PURE__ */ new Map(); | ||
var _a; | ||
this._headers = responseHeaders; | ||
const headers = this._headers.getAll("set-cookie"); | ||
for (const header of headers) { | ||
const parsed = parseSetCookieString(header); | ||
if (parsed) { | ||
const setCookie = ((_a = responseHeaders.getAll) == null ? void 0 : _a.call(responseHeaders, "set-cookie")) ?? responseHeaders.get("set-cookie") ?? []; | ||
const cookieStrings = Array.isArray(setCookie) ? setCookie : splitCookiesString(setCookie); | ||
for (const cookieString of cookieStrings) { | ||
const parsed = parseSetCookieString(cookieString); | ||
if (parsed) | ||
this._parsed.set(parsed.name, parsed); | ||
} | ||
} | ||
@@ -217,2 +218,53 @@ } | ||
} | ||
function splitCookiesString(cookiesString) { | ||
if (!cookiesString) | ||
return []; | ||
var cookiesStrings = []; | ||
var pos = 0; | ||
var start; | ||
var ch; | ||
var lastComma; | ||
var nextStart; | ||
var cookiesSeparatorFound; | ||
function skipWhitespace() { | ||
while (pos < cookiesString.length && /\s/.test(cookiesString.charAt(pos))) { | ||
pos += 1; | ||
} | ||
return pos < cookiesString.length; | ||
} | ||
function notSpecialChar() { | ||
ch = cookiesString.charAt(pos); | ||
return ch !== "=" && ch !== ";" && ch !== ","; | ||
} | ||
while (pos < cookiesString.length) { | ||
start = pos; | ||
cookiesSeparatorFound = false; | ||
while (skipWhitespace()) { | ||
ch = cookiesString.charAt(pos); | ||
if (ch === ",") { | ||
lastComma = pos; | ||
pos += 1; | ||
skipWhitespace(); | ||
nextStart = pos; | ||
while (pos < cookiesString.length && notSpecialChar()) { | ||
pos += 1; | ||
} | ||
if (pos < cookiesString.length && cookiesString.charAt(pos) === "=") { | ||
cookiesSeparatorFound = true; | ||
pos = nextStart; | ||
cookiesStrings.push(cookiesString.substring(start, lastComma)); | ||
start = pos; | ||
} else { | ||
pos = lastComma + 1; | ||
} | ||
} else { | ||
pos += 1; | ||
} | ||
} | ||
if (!cookiesSeparatorFound || pos >= cookiesString.length) { | ||
cookiesStrings.push(cookiesString.substring(start, cookiesString.length)); | ||
} | ||
} | ||
return cookiesStrings; | ||
} | ||
// Annotate the CommonJS export names for ESM import in node: | ||
@@ -219,0 +271,0 @@ 0 && (module.exports = { |
@@ -5,3 +5,3 @@ { | ||
"homepage": "https://edge-runtime.vercel.app/packages/cookies", | ||
"version": "3.0.2", | ||
"version": "3.0.3", | ||
"main": "dist/index.js", | ||
@@ -20,10 +20,19 @@ "module": "dist/index.mjs", | ||
"cookies", | ||
"set-cookie" | ||
"edge", | ||
"edge-runtime", | ||
"functions", | ||
"runtime", | ||
"set-cookie", | ||
"standard", | ||
"web" | ||
], | ||
"devDependencies": { | ||
"@edge-runtime/format": "1.1.0", | ||
"@edge-runtime/jest-environment": "2.0.2", | ||
"@edge-runtime/format": "2.0.0", | ||
"@edge-runtime/jest-environment": "2.0.3", | ||
"@types/cookie": "0.5.1", | ||
"tsup": "6" | ||
}, | ||
"engines": { | ||
"node": ">=14" | ||
}, | ||
"files": [ | ||
@@ -30,0 +39,0 @@ "dist" |
Sorry, the diff of this file is not supported yet
No README
QualityPackage does not have a README. This may indicate a failed publish or a low quality package.
Found 1 instance in 1 package
42527
6
689
0
37