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

Commit 7b45ecb

Browse files
committed
feat(setup redirects)
1 parent e326369 commit 7b45ecb

File tree

3 files changed

+16
-2
lines changed

3 files changed

+16
-2
lines changed

AFNetworking.d.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -780,7 +780,7 @@ declare class AFURLSessionManager extends NSObject implements NSCopying, NSSecur
780780

781781
setTaskNeedNewBodyStreamBlock(block: (p1: NSURLSession, p2: NSURLSessionTask) => NSInputStream): void;
782782

783-
setTaskWillPerformHTTPRedirectionBlock(block: (p1: NSURLSession, p2: NSURLSessionTask, p3: NSURLResponse, p4: NSURLRequest) => NSURLRequest): void;
783+
setTaskWillPerformHTTPRedirectionBlock(block: (p1: NSURLSession, p2: NSURLSessionTask, p3: NSURLResponse, p4: NSURLRequest) => NSURLRequest | null): void;
784784

785785
uploadProgressForTask(task: NSURLSessionTask): NSProgress;
786786

https.android.ts

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ let peer: Ipeer = {
1616
allowInvalidCertificates: false,
1717
validatesDomainName: true,
1818
}
19+
let followRedirects: boolean = true;
1920

2021
export function enableSSLPinning(options: Https.HttpsSSLPinningOptions) {
2122
if (!peer.host && !peer.certificate) {
@@ -57,13 +58,19 @@ export function disableSSLPinning() {
5758
}
5859
console.info('nativescript-https > Disabled SSL pinning by default')
5960

61+
export function setupRedirects(follow: boolean) {
62+
followRedirects = follow;
63+
getClient(true);
64+
}
65+
6066
let Client: okhttp3.OkHttpClient
6167
function getClient(reload: boolean = false): okhttp3.OkHttpClient {
6268
if (Client && reload == false) {
6369
return Client
6470
}
6571

66-
let client = new okhttp3.OkHttpClient.Builder()
72+
const client = new okhttp3.OkHttpClient.Builder().followRedirects(followRedirects);
73+
6774
if (peer.enabled == true) {
6875
if (peer.host || peer.certificate) {
6976
let spec = okhttp3.ConnectionSpec.MODERN_TLS

https.ios.ts

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ interface Ipolicies {
88
secured: boolean
99
secure?: AFSecurityPolicy
1010
}
11+
let followRedirects: boolean = true;
1112
let policies: Ipolicies = {
1213
def: AFSecurityPolicy.defaultPolicy(),
1314
secured: false,
@@ -34,6 +35,10 @@ export function disableSSLPinning() {
3435
}
3536
console.info('nativescript-https > Disabled SSL pinning by default')
3637

38+
export function setupRedirects(follow: boolean) {
39+
followRedirects = follow;
40+
}
41+
3742
function AFSuccess(resolve, task: NSURLSessionDataTask, data: NSDictionary<string, any> & NSData & NSArray<any>) {
3843
let content: any
3944
if (data && data.class) {
@@ -111,6 +116,8 @@ export function request(opts: Https.HttpsRequestOptions): Promise<Https.HttpsRes
111116
}
112117
}
113118

119+
manager.setTaskWillPerformHTTPRedirectionBlock((url, session, response, request) => followRedirects ? request : null);
120+
114121
let methods = {
115122
'GET': 'GETParametersSuccessFailure',
116123
'POST': 'POSTParametersSuccessFailure',

0 commit comments

Comments
 (0)