Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ https.get('https://yoursite.tld/yourpath', function(err, res){
}
});

var reqOptions = {method:'post', host:'yoursite.tld', path: '/yourpath', [port: 443], [headers: {header1: 'value1', header2: 'value2'}], [body: {}]};
var reqOptions = {
method: 'post',
host: 'yoursite.tld',
path: '/yourpath',
port: 443,
[headers: {header1: 'value1', header2: 'value2'}],
body: {},
timeout: 10000 // 10 sec.
};

https.request(reqOptions, function(err, res){
if (err){
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "cordova-plugin-pinnedhttps",
"version": "0.1.0",
"version": "0.1.1",
"description": "A Cordova plugin allowing you to make https requests, with (fingerprint-based) certificate pinning",
"main": "index.js",
"cordova": {
Expand Down
16 changes: 14 additions & 2 deletions src/ios/PinnedHTTPS.m
Original file line number Diff line number Diff line change
Expand Up @@ -269,8 +269,20 @@ - (void)req:(CDVInvokedUrlCommand*)command {
[self.commandDelegate sendPluginResult: rslt callbackId: command.callbackId];
return;
}
NSURL *reqUrl = [NSURL URLWithString: [NSString stringWithFormat:@"https://%@:%@%@", [options objectForKey:@"host"], [options objectForKey:@"port"], [options objectForKey:@"path"]]];
NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:reqUrl cachePolicy: NSURLRequestReloadIgnoringCacheData timeoutInterval: 20.0];
NSURL *reqUrl;
if ([[options objectForKey:@"port"] integerValue] == 80) {
reqUrl = [NSURL URLWithString: [NSString stringWithFormat:@"http://%@:%@%@", [options objectForKey:@"host"], [options objectForKey:@"port"], [options objectForKey:@"path"]]];
}
else {
reqUrl = [NSURL URLWithString: [NSString stringWithFormat:@"https://%@:%@%@", [options objectForKey:@"host"], [options objectForKey:@"port"], [options objectForKey:@"path"]]];
}
NSNumber *timeoutNumber = [options objectForKey:@"timeout"];
NSTimeInterval timeout = 20.0;
if (timeoutNumber != nil) {
timeout = [timeoutNumber doubleValue] / 1000;
}

NSMutableURLRequest *req = [NSMutableURLRequest requestWithURL:reqUrl cachePolicy: NSURLRequestReloadIgnoringCacheData timeoutInterval: timeout];
req.HTTPMethod = [method uppercaseString];
[req setValue: @"close" forHTTPHeaderField: @"Connection"];
[req setValue: @"utf-8" forHTTPHeaderField: @"Accept-Charset"];
Expand Down