chore(sdk): avoid invalid cookie blocking sending request (#8464)

This commit is contained in:
George He
2025-03-20 10:41:12 +08:00
committed by GitHub
parent 8b42ff9d52
commit 056a4bcf4c
2 changed files with 6 additions and 3 deletions

View File

@@ -2,6 +2,7 @@ import type { Cookie as InsomniaCookie, CookieJar as InsomniaCookieJar } from 'i
import { Cookie as ToughCookie } from 'tough-cookie';
import { v4 as uuidv4 } from 'uuid';
import { getExistingConsole } from './console';
import { Property, PropertyList } from './properties';
export interface InsomniaCookieExtensions {
@@ -242,7 +243,7 @@ export class CookieObject extends CookieList {
}
export class CookieJar {
// CookieJar from tough-cookie can not be used, as it will failed in comparing context location and cookies' domain
// CookieJar from tough-cookie can not be used, as it will fail in comparing context location and cookies' domain
// as it reads location from the browser window, it is "localhost"
private jar: Map<string, Map<string, Cookie>>; // Map<domain, Map<cookieKey, cookieObject>>
private jarName: string;
@@ -255,7 +256,8 @@ export class CookieJar {
cookies.forEach(cookie => {
const properties = cookie.toJSON();
if (!properties.domain) {
throw Error(`domain is not specified for the cookie ${cookie.key}`);
getExistingConsole().warn(`domain is not specified for the cookie "${cookie.key}" so it is omitted`);
return;
}
const domainCookies = this.jar.get(properties.domain) || new Map();

View File

@@ -1,3 +1,4 @@
import { getExistingConsole } from './console';
import { Property, PropertyList } from './properties';
import { Url, UrlMatchPattern, UrlMatchPatternList } from './urls';
@@ -202,7 +203,7 @@ export function transformToSdkProxyOptions(
if (bestProxy !== '') {
let sanitizedProxy = bestProxy;
if (bestProxy.indexOf('://') === -1) {
console.warn(`The protocol is missing and adding 'https:' protocol: ${bestProxy}`);
getExistingConsole().warn(`The protocol is missing for proxy, 'https:' is enabled for: ${bestProxy}`);
sanitizedProxy = 'https://' + bestProxy;
}