Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[TIMOB-19154]: iOS9 Deprecate NSURLConnection and replace with NSURLSession API #9366

Merged
merged 17 commits into from
Feb 23, 2018
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.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions iphone/Classes/APSHTTPClient/APSHTTPRequest.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,9 @@ typedef NS_ENUM(NSInteger, APSRequestError) {
@class APSHTTPRequest;
@class APSHTTPPostForm;

@protocol APSConnectionDelegate <NSURLConnectionDelegate, NSURLSessionDelegate, NSURLSessionDataDelegate>
@protocol APSConnectionDelegate <NSURLSessionDelegate, NSURLSessionDataDelegate>
@optional
-(BOOL)willHandleChallenge:(NSURLAuthenticationChallenge *)challenge forConnection:(NSURLConnection *)connection;
-(BOOL)willHandleChallenge:(NSURLAuthenticationChallenge *)challenge forSession:(NSURLSession *)session;
@end

@protocol APSHTTPRequestDelegate <NSObject>
Expand Down
Binary file modified iphone/Classes/APSHTTPClient/libAPSHTTPClient.a
Binary file not shown.
66 changes: 66 additions & 0 deletions tests/Resources/ti.network.httpclient.addontest.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
/*
* Appcelerator Titanium Mobile
* Copyright (c) 2011-Present by Appcelerator, Inc. All Rights Reserved.
* Licensed under the terms of the Apache Public License
* Please see the LICENSE included with this distribution for details.
*/
/* eslint-env mocha */
/* global Ti */
/* eslint no-unused-expressions: "off" */
'use strict';
var should = require('./utilities/assertions');

describe('Titanium.Network.HTTPClient', function () {
it.ios('basic-auth success', function (finish) {
var xhr, attempts;
this.timeout(6e4);
xhr = Ti.Network.createHTTPClient({
username: 'user',
password: 'passwd'
});
attempts = 3;
xhr.setTimeout(6e4);

xhr.onload = function () {
try {
should(this.responseText).be.a.string;
finish();
} catch (err) {
finish(err);
}
};
xhr.onerror = function (e) {
if (attempts-- > 0) {
Ti.API.warn('failed, attempting to retry request...');
xhr.send();
} else {
Ti.API.debug(JSON.stringify(e, null, 2));
finish(new Error('failed to authenticate: ' + e));
}
};

xhr.open('GET', 'http://httpbin.org/basic-auth/user/passwd');
xhr.send();
});

it.ios('basic-auth failure', function (finish) {
var xhr;
this.timeout(6e4);
xhr = Ti.Network.createHTTPClient({
username: 'user',
password: 'wrong_password',
});
xhr.setTimeout(6e4);

xhr.onload = function () {
finish(new Error('With wrong password it is authenticating'));
};
xhr.onerror = function () {
// This request should fail as password is wrong.
finish();
};

xhr.open('GET', 'http://httpbin.org/basic-auth/user/passwd');
xhr.send();
});
});