Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/https/request.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ const peer: Ipeer = {

let cache: okhttp3.Cache;
let forceCache = false;

export function setCache(options?: CacheOptions) {
if (options) {
forceCache = options.forceCache === true;
Expand All @@ -34,6 +35,7 @@ export function setCache(options?: CacheOptions) {
getClient(undefined, true);
}
}

export function clearCache() {
if (cache) {
cache.evictAll();
Expand Down
4 changes: 4 additions & 0 deletions src/https/request.common.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ export function getFilenameFromUrl(url: string) {

return result;
}

export function parseJSON(source: string): any {
const src = source.trim();
if (src.lastIndexOf(')') === src.length - 1) {
Expand All @@ -25,10 +26,13 @@ export function parseJSON(source: string): any {
}

export const interceptors = [];

export function addInterceptor(interceptor) {
interceptors.push(interceptor);
}

export const networkInterceptors = [];

export function addNetworkInterceptor(interceptor) {
networkInterceptors.push(interceptor);
}
22 changes: 14 additions & 8 deletions src/https/request.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ export function setCache(options?: CacheOptions) {
}
NSURLCache.sharedURLCache = cache;
}

export function clearCache() {
NSURLCache.sharedURLCache.removeAllCachedResponses();
}
Expand All @@ -31,7 +32,12 @@ const policies: Ipolicies = {
policies.def.allowInvalidCertificates = true;
policies.def.validatesDomainName = false;

const configuration = NSURLSessionConfiguration.defaultSessionConfiguration;
let manager = AFHTTPSessionManager.alloc().initWithSessionConfiguration(configuration);

export function enableSSLPinning(options: HttpsSSLPinningOptions) {
const url = NSURL.URLWithString(options.host);
manager = AFHTTPSessionManager.alloc().initWithSessionConfiguration(configuration).initWithBaseURL(url);
if (!policies.secure) {
policies.secure = AFSecurityPolicy.policyWithPinningMode(AFSSLPinningMode.PublicKey);
policies.secure.allowInvalidCertificates = Utils.isDefined(options.allowInvalidCertificates) ? options.allowInvalidCertificates : false;
Expand Down Expand Up @@ -298,8 +304,6 @@ function bodyToNative(cont) {
}
return dict;
}
const configuration = NSURLSessionConfiguration.defaultSessionConfiguration;
const manager = AFHTTPSessionManager.alloc().initWithSessionConfiguration(configuration);

const runningRequests: { [k: string]: NSURLSessionDataTask } = {};

Expand All @@ -308,10 +312,11 @@ export function cancelRequest(tag: string) {
runningRequests[tag].cancel();
}
}

export function cancelAllRequests() {
Object.values(runningRequests).forEach(request=>{
request.cancel()
})
Object.values(runningRequests).forEach((request) => {
request.cancel();
});
}

export function clearCookies() {
Expand Down Expand Up @@ -373,8 +378,8 @@ export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = tr

const progress = opts.onProgress
? (progress: NSProgress) => {
opts.onProgress(progress.completedUnitCount, progress.totalUnitCount);
}
opts.onProgress(progress.completedUnitCount, progress.totalUnitCount);
}
: null;
let task: NSURLSessionDataTask;
const tag = opts.tag;
Expand Down Expand Up @@ -500,7 +505,8 @@ export function request(opts: HttpsRequestOptions, useLegacy: boolean = true) {
}
});
}
//Android only

// Android only
export function getClient(opts: Partial<HttpsRequestOptions>) {
return undefined;
}