diff --git a/plugin.xml b/plugin.xml index c3f01cf..a1bde91 100644 --- a/plugin.xml +++ b/plugin.xml @@ -31,9 +31,6 @@ - - - diff --git a/src/ios/CordovaHttpPlugin.h b/src/ios/CordovaHttpPlugin.h index af5aa1f..917349a 100644 --- a/src/ios/CordovaHttpPlugin.h +++ b/src/ios/CordovaHttpPlugin.h @@ -4,11 +4,9 @@ @interface CordovaHttpPlugin : CDVPlugin -- (void)useBasicAuth:(CDVInvokedUrlCommand*)command; -- (void)setHeader:(CDVInvokedUrlCommand*)command; - (void)enableSSLPinning:(CDVInvokedUrlCommand*)command; - (void)acceptAllCerts:(CDVInvokedUrlCommand*)command; -- (void)acceptAllHosts:(CDVInvokedUrlCommand*)command; +- (void)validateDomainName:(CDVInvokedUrlCommand*)command; - (void)post:(CDVInvokedUrlCommand*)command; - (void)get:(CDVInvokedUrlCommand*)command; - (void)uploadFile:(CDVInvokedUrlCommand*)command; diff --git a/src/ios/CordovaHttpPlugin.m b/src/ios/CordovaHttpPlugin.m index eefaa45..01a1b0b 100644 --- a/src/ios/CordovaHttpPlugin.m +++ b/src/ios/CordovaHttpPlugin.m @@ -1,59 +1,45 @@ #import "CordovaHttpPlugin.h" #import "CDVFile.h" #import "TextResponseSerializer.h" -#import "HttpManager.h" +#import "AFHTTPSessionManager.h" @interface CordovaHttpPlugin() -- (void)setRequestHeaders:(NSDictionary*)headers; +- (void)setRequestHeaders:(NSDictionary*)headers forManager:(AFHTTPSessionManager*)manager; +- (void)setResults:(NSMutableDictionary*)dictionary withTask:(NSURLSessionTask*)task; @end @implementation CordovaHttpPlugin { - AFHTTPRequestSerializer *requestSerializer; + AFSecurityPolicy *securityPolicy; } - (void)pluginInitialize { - requestSerializer = [AFHTTPRequestSerializer serializer]; + securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; } -- (void)setRequestHeaders:(NSDictionary*)headers { - [HttpManager sharedClient].requestSerializer = [AFHTTPRequestSerializer serializer]; - [requestSerializer.HTTPRequestHeaders enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - [[HttpManager sharedClient].requestSerializer setValue:obj forHTTPHeaderField:key]; - }]; +- (void)setRequestHeaders:(NSDictionary*)headers forManager:(AFHTTPSessionManager*)manager { + manager.requestSerializer = [AFHTTPRequestSerializer serializer]; [headers enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { - [[HttpManager sharedClient].requestSerializer setValue:obj forHTTPHeaderField:key]; + [manager.requestSerializer setValue:obj forHTTPHeaderField:key]; }]; } -- (void)useBasicAuth:(CDVInvokedUrlCommand*)command { - NSString *username = [command.arguments objectAtIndex:0]; - NSString *password = [command.arguments objectAtIndex:1]; - - [requestSerializer setAuthorizationHeaderFieldWithUsername:username password:password]; - - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; -} - -- (void)setHeader:(CDVInvokedUrlCommand*)command { - NSString *header = [command.arguments objectAtIndex:0]; - NSString *value = [command.arguments objectAtIndex:1]; - - [requestSerializer setValue:value forHTTPHeaderField: header]; - - CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; - [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; +- (void)setResults:(NSMutableDictionary*)dictionary withTask:(NSURLSessionTask*)task { + if (task.response != nil) { + NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; + [dictionary setObject:[NSNumber numberWithInt:response.statusCode] forKey:@"status"]; + [dictionary setObject:response.allHeaderFields forKey:@"headers"]; + } } - (void)enableSSLPinning:(CDVInvokedUrlCommand*)command { bool enable = [[command.arguments objectAtIndex:0] boolValue]; if (enable) { - [HttpManager sharedClient].securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate]; + securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate]; } else { - [HttpManager sharedClient].securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; + securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; } CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; @@ -64,46 +50,41 @@ CDVPluginResult* pluginResult = nil; bool allow = [[command.arguments objectAtIndex:0] boolValue]; - [HttpManager sharedClient].securityPolicy.allowInvalidCertificates = allow; + securityPolicy.allowInvalidCertificates = allow; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } -- (void)acceptAllHosts:(CDVInvokedUrlCommand*)command { +- (void)validateDomainName:(CDVInvokedUrlCommand*)command { CDVPluginResult* pluginResult = nil; - bool allow = [[command.arguments objectAtIndex:0] boolValue]; - [HttpManager sharedClient].securityPolicy.validatesDomainName = !allow; + bool validate = [[command.arguments objectAtIndex:0] boolValue]; + + securityPolicy.validatesDomainName = validate; + pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } - (void)post:(CDVInvokedUrlCommand*)command { - HttpManager *manager = [HttpManager sharedClient]; + AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; + manager.securityPolicy = securityPolicy; NSString *url = [command.arguments objectAtIndex:0]; NSDictionary *parameters = [command.arguments objectAtIndex:1]; NSDictionary *headers = [command.arguments objectAtIndex:2]; - [self setRequestHeaders: headers]; + [self setRequestHeaders: headers forManager: manager]; CordovaHttpPlugin* __weak weakSelf = self; manager.responseSerializer = [TextResponseSerializer serializer]; [manager POST:url parameters:parameters progress:nil success:^(NSURLSessionTask *task, id responseObject) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; - if (task.response != nil) { - NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; - [dictionary setObject:[NSNumber numberWithInt:response.statusCode] forKey:@"status"]; - [dictionary setObject:response.allHeaderFields forKey:@"headers"]; - } + [self setResults: dictionary withTask: task]; [dictionary setObject:responseObject forKey:@"data"]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } failure:^(NSURLSessionTask *task, NSError *error) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; - if (task.response != nil) { - NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; - [dictionary setObject:[NSNumber numberWithInt:response.statusCode] forKey:@"status"]; - [dictionary setObject:response.allHeaderFields forKey:@"headers"]; - } + [self setResults: dictionary withTask: task]; [dictionary setObject:[error localizedDescription] forKey:@"error"]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; @@ -111,32 +92,25 @@ } - (void)get:(CDVInvokedUrlCommand*)command { - HttpManager *manager = [HttpManager sharedClient]; + AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; + manager.securityPolicy = securityPolicy; NSString *url = [command.arguments objectAtIndex:0]; NSDictionary *parameters = [command.arguments objectAtIndex:1]; NSDictionary *headers = [command.arguments objectAtIndex:2]; - [self setRequestHeaders: headers]; + [self setRequestHeaders: headers forManager: manager]; CordovaHttpPlugin* __weak weakSelf = self; manager.responseSerializer = [TextResponseSerializer serializer]; [manager GET:url parameters:parameters progress:nil success:^(NSURLSessionTask *task, id responseObject) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; - if (task.response != nil) { - NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; - [dictionary setObject:[NSNumber numberWithInt:response.statusCode] forKey:@"status"]; - [dictionary setObject:response.allHeaderFields forKey:@"headers"]; - } + [self setResults: dictionary withTask: task]; [dictionary setObject:responseObject forKey:@"data"]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } failure:^(NSURLSessionTask *task, NSError *error) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; - if (task.response != nil) { - NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; - [dictionary setObject:[NSNumber numberWithInt:response.statusCode] forKey:@"status"]; - [dictionary setObject:response.allHeaderFields forKey:@"headers"]; - } + [self setResults: dictionary withTask: task]; [dictionary setObject:[error localizedDescription] forKey:@"error"]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; @@ -144,32 +118,25 @@ } - (void)head:(CDVInvokedUrlCommand*)command { - HttpManager *manager = [HttpManager sharedClient]; + AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; + manager.securityPolicy = securityPolicy; NSString *url = [command.arguments objectAtIndex:0]; NSDictionary *parameters = [command.arguments objectAtIndex:1]; NSDictionary *headers = [command.arguments objectAtIndex:2]; - [self setRequestHeaders: headers]; + [self setRequestHeaders: headers forManager: manager]; CordovaHttpPlugin* __weak weakSelf = self; manager.responseSerializer = [AFHTTPResponseSerializer serializer]; [manager HEAD:url parameters:parameters success:^(NSURLSessionTask *task) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; - if (task.response != nil) { - NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; - [dictionary setObject:[NSNumber numberWithInt:response.statusCode] forKey:@"status"]; - [dictionary setObject:response.allHeaderFields forKey:@"headers"]; - } + [self setResults: dictionary withTask: task]; // no 'body' for HEAD request, omitting 'data' CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } failure:^(NSURLSessionTask *task, NSError *error) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; - if (task.response != nil) { - NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; - [dictionary setObject:[NSNumber numberWithInt:response.statusCode] forKey:@"status"]; - [dictionary setObject:response.allHeaderFields forKey:@"headers"]; - } + [self setResults: dictionary withTask: task]; [dictionary setObject:[error localizedDescription] forKey:@"error"]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; @@ -177,7 +144,8 @@ } - (void)uploadFile:(CDVInvokedUrlCommand*)command { - HttpManager *manager = [HttpManager sharedClient]; + AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; + manager.securityPolicy = securityPolicy; NSString *url = [command.arguments objectAtIndex:0]; NSDictionary *parameters = [command.arguments objectAtIndex:1]; NSDictionary *headers = [command.arguments objectAtIndex:2]; @@ -186,7 +154,7 @@ NSURL *fileURL = [NSURL fileURLWithPath: filePath]; - [self setRequestHeaders: headers]; + [self setRequestHeaders: headers forManager: manager]; CordovaHttpPlugin* __weak weakSelf = self; manager.responseSerializer = [TextResponseSerializer serializer]; @@ -203,20 +171,12 @@ } } progress:nil success:^(NSURLSessionTask *task, id responseObject) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; - if (task.response != nil) { - NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; - [dictionary setObject:[NSNumber numberWithInt:response.statusCode] forKey:@"status"]; - [dictionary setObject:response.allHeaderFields forKey:@"headers"]; - } + [self setResults: dictionary withTask: task]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } failure:^(NSURLSessionTask *task, NSError *error) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; - if (task.response != nil) { - NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; - [dictionary setObject:[NSNumber numberWithInt:response.statusCode] forKey:@"status"]; - [dictionary setObject:response.allHeaderFields forKey:@"headers"]; - } + [self setResults: dictionary withTask: task]; [dictionary setObject:[error localizedDescription] forKey:@"error"]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; @@ -225,13 +185,14 @@ - (void)downloadFile:(CDVInvokedUrlCommand*)command { - HttpManager *manager = [HttpManager sharedClient]; + AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; + manager.securityPolicy = securityPolicy; NSString *url = [command.arguments objectAtIndex:0]; NSDictionary *parameters = [command.arguments objectAtIndex:1]; NSDictionary *headers = [command.arguments objectAtIndex:2]; NSString *filePath = [command.arguments objectAtIndex: 3]; - [self setRequestHeaders: headers]; + [self setRequestHeaders: headers forManager: manager]; if ([filePath hasPrefix:@"file://"]) { filePath = [filePath substringFromIndex:7]; @@ -291,21 +252,13 @@ id filePlugin = [self.commandDelegate getCommandInstance:@"File"]; NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; - if (task.response != nil) { - NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; - [dictionary setObject:[NSNumber numberWithInt:response.statusCode] forKey:@"status"]; - [dictionary setObject:response.allHeaderFields forKey:@"headers"]; - } + [self setResults: dictionary withTask: task]; [dictionary setObject:[filePlugin getDirectoryEntry:filePath isDirectory:NO] forKey:@"file"]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; } failure:^(NSURLSessionTask *task, NSError *error) { NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; - if (task.response != nil) { - NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; - [dictionary setObject:[NSNumber numberWithInt:response.statusCode] forKey:@"status"]; - [dictionary setObject:response.allHeaderFields forKey:@"headers"]; - } + [self setResults: dictionary withTask: task]; [dictionary setObject:[error localizedDescription] forKey:@"error"]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; diff --git a/src/ios/HTTPManager.h b/src/ios/HTTPManager.h deleted file mode 100644 index 9367bbe..0000000 --- a/src/ios/HTTPManager.h +++ /dev/null @@ -1,28 +0,0 @@ -// Copyright (c) 2012 Mattt Thompson (http://mattt.me/) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// Modified by Andrew Stephan -#import -#import "AFHTTPSessionManager.h" - -@interface HttpManager : AFHTTPSessionManager - -+ (instancetype)sharedClient; - -@end \ No newline at end of file diff --git a/src/ios/HTTPManager.m b/src/ios/HTTPManager.m deleted file mode 100644 index 5d2b294..0000000 --- a/src/ios/HTTPManager.m +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright (c) 2012 Mattt Thompson (http://mattt.me/) -// -// Permission is hereby granted, free of charge, to any person obtaining a copy -// of this software and associated documentation files (the "Software"), to deal -// in the Software without restriction, including without limitation the rights -// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell -// copies of the Software, and to permit persons to whom the Software is -// furnished to do so, subject to the following conditions: -// -// The above copyright notice and this permission notice shall be included in -// all copies or substantial portions of the Software. -// -// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR -// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, -// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE -// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER -// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, -// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN -// THE SOFTWARE. -// Modified by Andrew Stephan -#import "HttpManager.h" - -@implementation HttpManager - -+ (instancetype)sharedClient { - static HttpManager *_sharedClient = nil; - static dispatch_once_t onceToken; - dispatch_once(&onceToken, ^{ - _sharedClient = [HttpManager manager]; - }); - - return _sharedClient; -} - -@end \ No newline at end of file diff --git a/www/cordovaHTTP.js b/www/cordovaHTTP.js index 8c3db92..92942c2 100644 --- a/www/cordovaHTTP.js +++ b/www/cordovaHTTP.js @@ -6,12 +6,36 @@ var exec = require('cordova/exec'); +// Thanks Mozilla: https://developer.mozilla.org/en-US/docs/Web/API/WindowBase64/Base64_encoding_and_decoding#The_.22Unicode_Problem.22 +function b64EncodeUnicode(str) { + return btoa(encodeURIComponent(str).replace(/%([0-9A-F]{2})/g, function(match, p1) { + return String.fromCharCode('0x' + p1); + })); +} + +function mergeHeaders(globalHeaders, localHeaders) { + var globalKeys = Object.keys(globalHeaders); + var key; + for (var i = 0; i < globalKeys.length; i++) { + key = globalKeys[i]; + if (!localHeaders.hasOwnProperty(key)) { + localHeaders[key] = globalHeaders[key]; + } + } + return localHeaders; +} + var http = { - useBasicAuth: function(username, password, success, failure) { - return exec(success, failure, "CordovaHttpPlugin", "useBasicAuth", [username, password]); + headers: {}, + sslPinning: false, + getBasicAuthHeader: function(username, password) { + return {'Authorization': 'Basic ' + b64EncodeUnicode(username + ':' + password)}; }, - setHeader: function(header, value, success, failure) { - return exec(success, failure, "CordovaHttpPlugin", "setHeader", [header, value]); + useBasicAuth: function(username, password) { + this.headers.Authorization = 'Basic ' + b64EncodeUnicode(username + ':' + password); + }, + setHeader: function(header, value) { + this.headers[header] = value; }, enableSSLPinning: function(enable, success, failure) { return exec(success, failure, "CordovaHttpPlugin", "enableSSLPinning", [enable]); @@ -19,19 +43,23 @@ var http = { acceptAllCerts: function(allow, success, failure) { return exec(success, failure, "CordovaHttpPlugin", "acceptAllCerts", [allow]); }, - acceptAllHosts: function(allow, success, failure) { - return exec(success, failure, "CordovaHttpPlugin", "acceptAllHosts", [allow]); + validateDomainName: function(validate, success, failure) { + return exec(success, failure, "CordovaHttpPlugin", "validateDomainName", [validate]); }, post: function(url, params, headers, success, failure) { + headers = mergeHeaders(this.headers, headers); return exec(success, failure, "CordovaHttpPlugin", "post", [url, params, headers]); }, get: function(url, params, headers, success, failure) { + headers = mergeHeaders(this.headers, headers); return exec(success, failure, "CordovaHttpPlugin", "get", [url, params, headers]); }, head: function(url, params, headers, success, failure) { + headers = mergeHeaders(this.headers, headers); return exec(success, failure, "CordovaHttpPlugin", "head", [url, params, headers]); }, uploadFile: function(url, params, headers, filePath, name, success, failure) { + headers = mergeHeaders(this.headers, headers); return exec(success, failure, "CordovaHttpPlugin", "uploadFile", [url, params, headers, filePath, name]); }, downloadFile: function(url, params, headers, filePath, success, failure) { @@ -57,6 +85,7 @@ var http = { * Modified by Andrew Stephan for Sync OnSet * */ + headers = mergeHeaders(this.headers, headers); var win = function(result) { var entry = new (require('cordova-plugin-file.FileEntry'))(); entry.isDirectory = false; @@ -107,20 +136,17 @@ if (typeof angular !== "undefined") { } var cordovaHTTP = { - useBasicAuth: function(username, password) { - return makePromise(http.useBasicAuth, [username, password]); - }, - setHeader: function(header, value) { - return makePromise(http.setHeader, [header, value]); - }, + getBasicAuthHeader: http.getBasicAuthHeader, + useBasicAuth: http.useBasicAuth, + setHeader: http.setHeader, enableSSLPinning: function(enable) { return makePromise(http.enableSSLPinning, [enable]); }, acceptAllCerts: function(allow) { return makePromise(http.acceptAllCerts, [allow]); }, - acceptAllHosts: function(allow) { - return makePromise(http.acceptAllHosts, [allow]); + validateDomainName: function(validate) { + return makePromise(http.validateDomainName, [validate]); }, post: function(url, params, headers) { return makePromise(http.post, [url, params, headers], true);