Skip to content

Commit

Permalink
feat: export getClient for use with ui-image plugin
Browse files Browse the repository at this point in the history
  • Loading branch information
farfromrefug committed Sep 17, 2022
1 parent dff1c3a commit 50a5f4a
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 5 deletions.
11 changes: 6 additions & 5 deletions src/request.android.ts
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ export function setCache(options?: CacheOptions) {
cache = null;
}
if (Client) {
getClient(true);
//we need to force a new client for the builder to use cache
getClient(undefined, true);
}
}
export function clearCache() {
Expand Down Expand Up @@ -221,18 +222,18 @@ export function enableSSLPinning(options: HttpsSSLPinningOptions) {
}
}
peer.enabled = true;
getClient(true);
getClient(undefined, true);
}

export function disableSSLPinning() {
peer.enabled = false;
getClient(true);
getClient(undefined, true);
}

let Client: okhttp3.OkHttpClient;
let cookieJar: com.nativescript.https.QuotePreservingCookieJar;
let cookieManager: java.net.CookieManager;
function getClient(reload: boolean = false, opts: Partial<HttpsRequestOptions> = {}): okhttp3.OkHttpClient {
export function getClient(opts: Partial<HttpsRequestOptions> = {}, reload: boolean = false): okhttp3.OkHttpClient {
if (!Client) {
// ssl error fix on KitKat. Only need to be done once.
// client will be null only onced so will run only once
Expand Down Expand Up @@ -409,7 +410,7 @@ const runningClients: { [k: string]: okhttp3.OkHttpClient } = {};

let OkHttpResponse: typeof com.nativescript.https.OkHttpResponse;
export function createRequest(opts: HttpsRequestOptions, useLegacy: boolean = true): HttpsRequest {
const client = getClient(false, opts);
const client = getClient(opts, false);

const request = new okhttp3.Request.Builder();
request.url(opts.url);
Expand Down
2 changes: 2 additions & 0 deletions src/request.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -110,4 +110,6 @@ export function clearCache();
export function createRequest(opts: HttpsRequestOptions): HttpsRequest;
export function cancelRequest(tag: string);
export function addNetworkInterceptor(interceptor);

export function getClient(opts: Partial<HttpsRequestOptions>);
export * from './request.common';
4 changes: 4 additions & 0 deletions src/request.ios.ts
Original file line number Diff line number Diff line change
Expand Up @@ -488,3 +488,7 @@ export function request(opts: HttpsRequestOptions, useLegacy: boolean = true) {
}
});
}
//Android only
export function getClient(opts: Partial<HttpsRequestOptions>) {
return undefined;
}

0 comments on commit 50a5f4a

Please sign in to comment.