Skip to content
This repository was archived by the owner on Jul 30, 2023. It is now read-only.

Commit 41c3418

Browse files
committed
fix(resolveCookieString fn resolver)
1 parent 3607c7c commit 41c3418

File tree

11 files changed

+68
-80
lines changed

11 files changed

+68
-80
lines changed

cookie.android.js

Lines changed: 0 additions & 17 deletions
This file was deleted.

cookie.android.ts

Lines changed: 0 additions & 16 deletions
This file was deleted.

cookie.ios.js

Lines changed: 0 additions & 14 deletions
This file was deleted.

cookie.ios.ts

Lines changed: 0 additions & 12 deletions
This file was deleted.

cookie.common.js renamed to cookie.js

Lines changed: 28 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

cookie.common.ts renamed to cookie.ts

Lines changed: 31 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,9 @@
11
import { Headers } from 'tns-core-modules/http';
2-
import { isAndroid } from 'tns-core-modules/platform';
32
import { HttpsResponse } from './https.common';
3+
import { isAndroid } from 'tns-core-modules/platform';
44
import * as AppSettings from 'tns-core-modules/application-settings';
55
const MobileStorageCookieStore = require('tough-cookie-mobile-storage-store');
66
import { CookieJar } from 'tough-cookie-no-native';
7-
import { resolveCookieString as resolveCookieStringIOS } from './cookie.ios';
8-
import { resolveCookieString as resolveCookieStringAndroid } from './cookie.android';
97

108
const STORE_KEY = 'NS_COOKIE_STORE';
119

@@ -17,6 +15,36 @@ class NSStorageWrapper {
1715
const store = new MobileStorageCookieStore(new NSStorageWrapper(), STORE_KEY);
1816
export const cookieJar = new CookieJar(store);
1917

18+
export function resolveCookieStringAndroid(headers: okhttp3.Headers): string[] {
19+
const searchReg = /^set-cookie$/i;
20+
const length: number = headers.size();
21+
22+
let result: string[] = [];
23+
24+
for (let i = 0; i < length; i++) {
25+
const key = headers.name(i);
26+
if (key.match(searchReg)) {
27+
const value = headers.value(i);
28+
result = [...result, value];
29+
}
30+
}
31+
32+
return result;
33+
}
34+
35+
export function resolveCookieStringIOS(headers: NSDictionary<any, any>): string[] {
36+
const searchReg = /^set-cookie$/i;
37+
let result: string[] = [];
38+
39+
headers.enumerateKeysAndObjectsUsingBlock((key, value) => {
40+
if (key.match(searchReg)) {
41+
result = [...result, value];
42+
}
43+
});
44+
45+
return result;
46+
}
47+
2048
export function handleCookie(url: string, headers: okhttp3.Headers | NSDictionary<any, any>): void {
2149
const cookies = isAndroid
2250
? resolveCookieStringAndroid(<okhttp3.Headers>headers)

https.android.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

https.android.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as application from 'tns-core-modules/application';
22
import { HttpRequestOptions, Headers, HttpResponse } from 'tns-core-modules/http';
33
import { isDefined, isNullOrUndefined, isObject } from 'tns-core-modules/utils/types';
44
import * as Https from './https.common';
5-
import { handleCookie, mergeRequestHeaders } from './cookie.common';
5+
import { handleCookie, mergeRequestHeaders } from './cookie';
66

77
interface Ipeer {
88
enabled: boolean;

https.ios.js

Lines changed: 3 additions & 3 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

https.ios.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import * as application from 'tns-core-modules/application';
22
import { HttpRequestOptions, Headers, HttpResponse } from 'tns-core-modules/http';
33
import { isDefined, isNullOrUndefined, isObject, isString } from 'tns-core-modules/utils/types';
44
import * as Https from './https.common';
5-
import { handleCookie, mergeRequestHeaders } from './cookie.common';
5+
import { handleCookie, mergeRequestHeaders } from './cookie';
66

77
const methods = {
88
GET: 'GETParametersSuccessFailure',

0 commit comments

Comments
 (0)