|
|
@@ -237,6 +237,73 @@ function MagicJS(scriptName = "MagicJS", logLevel = "INFO") {
|
|
|
return $response.body;
|
|
|
}
|
|
|
}
|
|
|
+
|
|
|
+ // 解析cookie字符串的函数
|
|
|
+ parseCookies(cookieString) {
|
|
|
+ let dict = {};
|
|
|
+ cookieString && cookieString.split(';').forEach(function(cookie) {
|
|
|
+ let parts = cookie.split('=');
|
|
|
+ dict[parts.shift().trim()] = decodeURI(parts.join('='));
|
|
|
+ });
|
|
|
+ return dict;
|
|
|
+ }
|
|
|
+
|
|
|
+ // 系列化为cookie字符串
|
|
|
+ serializeCookies(cookieData) {
|
|
|
+ const parts = [];
|
|
|
+ for(let key in cookieData){
|
|
|
+ let value = cookieData[key];
|
|
|
+ let cookiePart = `${encodeURIComponent(key)}=${encodeURIComponent(value)}`;
|
|
|
+ parts.push(cookiePart);
|
|
|
+ }
|
|
|
+ return parts.join('; ');
|
|
|
+ }
|
|
|
+
|
|
|
+ parseSetCookies(cookieString) {
|
|
|
+ const attribKeys = ['Expires', 'Max-Age', 'Domain', 'Path', 'HttpOnly', 'SameSite'];
|
|
|
+ const parts = cookieString.split(';');
|
|
|
+ let mainKey = null;
|
|
|
+ const retDict = {};
|
|
|
+ const retData = [];
|
|
|
+ parts.forEach(part => {
|
|
|
+ let pstr = part.trim();
|
|
|
+ let aKey = null;
|
|
|
+ let aValue = true;
|
|
|
+
|
|
|
+ if (pstr.includes('=')) {
|
|
|
+ kvdata = pstr.split('=');
|
|
|
+ aKey = kvdata[0].trim();
|
|
|
+ aValue = kvdata[1].trim();
|
|
|
+ } else {
|
|
|
+ aKey = pstr;
|
|
|
+ }
|
|
|
+
|
|
|
+ if (attribKeys.includes(aKey)) {
|
|
|
+ if (retDict[mainKey]) {
|
|
|
+ retDict[mainKey][aKey] = aValue;
|
|
|
+ attribs = retDict[mainKey].attribs;
|
|
|
+ attribs[aKey] = aValue;
|
|
|
+ }
|
|
|
+ } else {
|
|
|
+ mainKey = aKey;
|
|
|
+ let attribs = {};
|
|
|
+ if (mainKey.includes(',')) {
|
|
|
+ const keys = mainKey.split(',');
|
|
|
+ keys.forEach(key => {
|
|
|
+ const k = key.trim();
|
|
|
+ if (attribKeys.includes(k)) {
|
|
|
+ attribs[k] = true;
|
|
|
+ } else {
|
|
|
+ mainKey = k;
|
|
|
+ }
|
|
|
+ });
|
|
|
+ }
|
|
|
+ retDict[mainKey] = { name: mainKey, value: aValue, attribs: attribs };
|
|
|
+ retData.push(retDict[mainKey]);
|
|
|
+ }
|
|
|
+ });
|
|
|
+ return retData;
|
|
|
+ }
|
|
|
objToQueryStr(obj, encode) {
|
|
|
let str = '';
|
|
|
for (const key in obj) {
|