Stub in new SSL implemenation for Apple OS#1239
Open
singpolyma wants to merge 1 commit intoHaxeFoundation:masterfrom
Open
Stub in new SSL implemenation for Apple OS#1239singpolyma wants to merge 1 commit intoHaxeFoundation:masterfrom
singpolyma wants to merge 1 commit intoHaxeFoundation:masterfrom
Conversation
Use native SSL on Apple OS instead of mbedtls. Especially needed on iOS where the root CA store cannot be read.
Contributor
|
I think using OS SSL libraries where possible is a good idea (I've got a pending merge in #1135 which does it for Windows) and have looked at this mac library before, I've got a few comments though.
|
Contributor
|
I think best solution is using native http api of apple os. The sample code is a nme wrapper, so it requires a few changes to compile. #if ios
private function iOSResponse(data:NSData, response:NSURLResponse, error:NSError)
{
var statusCode = -1;
if (response != null) {
var httpResponse:NSHTTPURLResponse = untyped __cpp__("(NSHTTPURLResponse *) {0}", response);
statusCode = httpResponse.statusCode;
}
var shouldRetry = (error != null) || (statusCode >= 500);
if (shouldRetry && retryCount < maxRetries)
{
retryCount++;
Sys.println('${urlRequest.url} request failed, retrying... Attempt ${retryCount} status code ${statusCode}');
runiOS();
return;
}
if (error != null || statusCode >= 400)
{
onError(error != null ? error.localizedDescription.toString() : '${statusCode}');
return;
}
onStatus(statusCode);
retryCount = 0;
var bytes = data.toBytes();
if (urlLoader.dataFormat== URLLoaderDataFormat.BINARY)
{
byteData = ByteArray.fromBytes(bytes);
}
else
{
stringData = bytes.getString(0, bytes.length, UTF8);
}
state = URLLoader.urlComplete;
}
public function runiOS() {
var url:NSURL = NSURL.URLWithString(this.urlRequest.url);
var request:NSMutableURLRequest = NSMutableURLRequest.requestWithURL(url);
for(header in headers.keys())
{
var value:String = Std.string(headers.get(header));
request.setValueForHTTPHeaderField(value, header);
}
var session:NSURLSession = NSURLSession.sharedSession();
var task:NSURLSessionDataTask = session.dataTaskWithRequestCompletionHandler(request, untyped __cpp__('^(NSData *data, NSURLResponse *response, NSError *error) {
dispatch_async(dispatch_get_main_queue(), ^{
{0}(data, response, error);
});
}', iOSResponse));
task.resume();
}
#end |
Author
|
@barisyild that's only going to work for HTTP things. Besides that making that fit within a cross platform http context may not always work either vs just replacing the lower level abstraction that haxe already has with something working. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Use native SSL on Apple OS instead of mbedtls. Especially needed on iOS where the root CA store cannot be read.
Fixes #570