@softtynet/zca-js 2.1.4 → 2.1.8
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/cjs/utils.cjs +14 -8
- package/dist/utils.js +14 -8
- package/package.json +1 -1
package/dist/cjs/utils.cjs
CHANGED
|
@@ -308,16 +308,22 @@ async function request(ctx, url, options, raw = false) {
|
|
|
308
308
|
const response = await ctx.options.polyfill(url, _options);
|
|
309
309
|
const setCookieRaw = response.headers.get("set-cookie");
|
|
310
310
|
if (setCookieRaw && !raw) {
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
//
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
311
|
+
let cookieStrings = [];
|
|
312
|
+
const headers = response.headers;
|
|
313
|
+
// Cách 1: Ưu tiên lấy Mảng Raw chuẩn gốc (Array) của thư viện node-fetch
|
|
314
|
+
if (typeof headers.raw === "function") {
|
|
315
|
+
const rawHeaders = headers.raw();
|
|
316
|
+
if (rawHeaders && rawHeaders["set-cookie"]) {
|
|
317
|
+
cookieStrings = rawHeaders["set-cookie"];
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
// Cách 2: Nếu dùng Fetch API Native của NodeJS 18+
|
|
321
|
+
else if (typeof headers.getSetCookie === "function") {
|
|
322
|
+
cookieStrings = headers.getSetCookie();
|
|
318
323
|
}
|
|
324
|
+
// Cách 3: Fallback dùng Regex Lookahead an toàn (Không bao giờ tách nhầm dấu phẩy của Expires date)
|
|
319
325
|
else {
|
|
320
|
-
cookieStrings = setCookieRaw.split(
|
|
326
|
+
cookieStrings = setCookieRaw.split(/,\s*(?=[a-zA-Z0-9_-]+\s*=)/);
|
|
321
327
|
}
|
|
322
328
|
for (const cookie of cookieStrings) {
|
|
323
329
|
const parsed = toughCookie.Cookie.parse(cookie);
|
package/dist/utils.js
CHANGED
|
@@ -304,16 +304,22 @@ export async function request(ctx, url, options, raw = false) {
|
|
|
304
304
|
const response = await ctx.options.polyfill(url, _options);
|
|
305
305
|
const setCookieRaw = response.headers.get("set-cookie");
|
|
306
306
|
if (setCookieRaw && !raw) {
|
|
307
|
-
|
|
308
|
-
|
|
309
|
-
//
|
|
310
|
-
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
307
|
+
let cookieStrings = [];
|
|
308
|
+
const headers = response.headers;
|
|
309
|
+
// Cách 1: Ưu tiên lấy Mảng Raw chuẩn gốc (Array) của thư viện node-fetch
|
|
310
|
+
if (typeof headers.raw === "function") {
|
|
311
|
+
const rawHeaders = headers.raw();
|
|
312
|
+
if (rawHeaders && rawHeaders["set-cookie"]) {
|
|
313
|
+
cookieStrings = rawHeaders["set-cookie"];
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
// Cách 2: Nếu dùng Fetch API Native của NodeJS 18+
|
|
317
|
+
else if (typeof headers.getSetCookie === "function") {
|
|
318
|
+
cookieStrings = headers.getSetCookie();
|
|
314
319
|
}
|
|
320
|
+
// Cách 3: Fallback dùng Regex Lookahead an toàn (Không bao giờ tách nhầm dấu phẩy của Expires date)
|
|
315
321
|
else {
|
|
316
|
-
cookieStrings = setCookieRaw.split(
|
|
322
|
+
cookieStrings = setCookieRaw.split(/,\s*(?=[a-zA-Z0-9_-]+\s*=)/);
|
|
317
323
|
}
|
|
318
324
|
for (const cookie of cookieStrings) {
|
|
319
325
|
const parsed = toughCookie.Cookie.parse(cookie);
|