Compare commits

...
88 Commits
Author SHA1 Message Date
Sefa Ilkimen 1375727316 release v1.6.2 2017-10-19 17:58:48 +02:00
Sefa Ilkimen d136d90893 - improved release process (using npm script)
- updated version number
2017-10-19 17:56:30 +02:00
Sefa Ilkimen a8f1d2b1c2 changed behaviour #29: removed "validateDomainName" function and disabling it when "acceptAllCerts" is enabled 2017-10-19 16:24:54 +02:00
Sefa IlkimenandGitHub c29ce85df3 Merge pull request #28 from ryandegruyter/patch-1
(iOS) Add support for Content-Type application/hal+json
2017-10-19 09:42:13 +02:00
Sefa Ilkimen aeefc9f5ef tests: increased timeout value because test vm takes long time to spin up 2017-10-16 10:57:05 +02:00
Sefa Ilkimen 4ea9c24d6d travis config: added travis_wait to prevent timeout issue 2017-10-16 10:17:05 +02:00
Sefa Ilkimen 7037fd2fa7 - improved test app
- defined new tests
2017-10-13 16:30:48 +02:00
Sefa Ilkimen 6f210a70fb fixed issue #31 - request fails throwing error on erroneous cookies 2017-10-13 12:16:29 +02:00
Sefa Ilkimen 10eb102d43 fixed travis config (jwt section) 2017-10-12 09:08:03 +02:00
Sefa Ilkimen 9dc0bd56e0 WIP: integrating saucelabs tests 2017-10-11 16:33:07 +02:00
Ryan de GruyterandGitHub 190c44b30a Add support for Content-Type application/hal+json
Currently when the server responds with a content type of application/hal+json, the response might be 200 but the AFNetwork will call the fail callback anyway because the content type is not acceptable.
2017-10-09 13:34:40 +02:00
Sefa Ilkimen 807af7adfa release 1.6.1 2017-10-04 13:01:50 +02:00
Sefa Ilkimen dd66698f96 updated version number 2017-10-04 13:00:32 +02:00
Sefa Ilkimen 3476ff7ffb added script which is updating version number in plugin.xml automatically 2017-10-04 12:59:33 +02:00
Sefa Ilkimen 52b2efe71b fixed PATCH method on android 2017-10-02 16:17:29 +02:00
Sefa Ilkimen 8b4c6de4b9 implemented PATCH method for iOS 2017-10-02 12:29:55 +02:00
Sefa Ilkimen 3138d423ee temporary removed patch method in www interface 2017-10-02 11:09:05 +02:00
Sefa IlkimenandGitHub f0194ad55a Merge pull request #22 from akhatri/feature-patch-method-android
Feature patch method android
2017-10-02 10:50:12 +02:00
Akshat Khatri - AK 09da3c9a97 patch method android 2017-10-01 17:26:20 +11:00
Akshat Khatri - AK 52ccfc6aca Merge remote-tracking branch 'refs/remotes/silkimen/master' into feature-patch-method-android 2017-10-01 17:11:41 +11:00
Sefa Ilkimen fc89a64675 update changelog and version number 2017-09-29 16:42:36 +02:00
Sefa Ilkimen 4954385361 - fix issue #16: removed build script and prebuild hook
- implement release script
2017-09-29 16:35:34 +02:00
Sefa IlkimenandGitHub 08554c02cb Merge pull request #21 from kesozjura/master
Add global redirection control
2017-09-29 15:51:56 +02:00
Martin Kasa 18a2fc0c69 temporary umd-tough-cookie.js fix 2017-09-29 14:44:44 +02:00
Martin Kasa a4a6440bcb Add global redirection control
copied from https://github.com/wymsee/cordova-HTTP/pull/137
2017-09-29 14:36:00 +02:00
Akshat Khatri - AK 792515e1c6 patch method android 2017-09-29 21:02:44 +10:00
Sefa Ilkimen 66dc8ff2ca changed readme file 2017-09-26 10:48:06 +02:00
Sefa Ilkimen 91b35d561c - updated version number
- updated change log
2017-09-26 10:38:16 +02:00
Sefa IlkimenandGitHub 45c0f8937f Merge pull request #14 from RangerRick/fix-serialization
change setParamSerializer to setDataSerializer (fixes #13)
2017-09-26 11:15:19 +03:00
Sefa IlkimenandGitHub b1c8427986 Merge pull request #15 from RangerRick/documentation-updates
add missing documentation
2017-09-26 11:05:34 +03:00
Benjamin Reed 91470725ee add missing documentation for setRequestTimeout, removeCookies, and head 2017-09-25 16:12:40 -04:00
Benjamin Reed 7cb41e0c1b change setParamSerializer to setDataSerializer (fixes #13) 2017-09-25 14:51:57 -04:00
Sefa Ilkimen ee8cae88a9 updated change log 2017-09-12 19:05:23 +03:00
Sefa IlkimenandGitHub aa8105948e Merge pull request #10 from DayBr3ak/master
fix gzip decompression when request header accepts gzip compression
2017-09-12 19:00:31 +03:00
ben 325a2e6200 fix gzip decompression when request header accepts gzip compression 2017-09-12 14:17:52 +02:00
Sefa Ilkimen 8ac8b95246 updated version number 2017-08-21 00:35:24 +02:00
Sefa Ilkimen 5a7f09bc44 updated change log 2017-08-21 00:31:50 +02:00
Sefa Ilkimen 308c49635b added build batch 2017-08-21 00:23:32 +02:00
Sefa Ilkimen d2a5a113c6 added slack integration 2017-08-21 00:17:30 +02:00
Sefa Ilkimen 2c4ce6f8c7 fixed travis filename 2017-08-20 23:49:58 +02:00
Sefa Ilkimen 613593ba51 added travis integration (doing test installation) 2017-08-20 23:44:21 +02:00
Jochen Becker a20821378b - if a request timed out the same error codes are returned for iOS and Android
- updated change log
2017-08-14 17:05:44 +02:00
Sefa Ilkimen 5535464db2 updated change log 2017-08-13 03:05:22 +02:00
Sefa Ilkimen 7ded66d4b8 fix issue #2: handling "expires" key case-insensitive 2017-08-13 03:01:52 +02:00
Jochen Becker d84a222dda - added function "setRequestTimeout" to set the timeout for all further requests and to prevent to "wait forever" on Android in case the server is not responding
- updated change log
- incremented version for release
2017-08-10 10:03:38 +02:00
Jochen Becker 14eef1ca66 - convert response header keys to lowercase (iOS only)
- updated change log
- incremented version for release
2017-05-31 08:50:13 +02:00
Jochen Becker cf5a684d51 - added a function to remove all cookies for a URL
- updated change log
- incremented version for release
2017-05-23 10:26:51 +02:00
Jochen Becker c153378b4b - fixed an error if the response has no "headers" field
- updated change log
- incremented version for release
2017-03-03 11:11:04 +01:00
Sefa Ilkimen 8092e8b025 - updated change log
- incremented version for release
2016-12-19 15:32:13 +01:00
Sefa Ilkimen afb4ea6199 - handles cookies correctly on non-success response from server
- throws error when a callback function is missing
2016-12-12 14:09:41 +01:00
Sefa Ilkimen 2c8c8a14a5 - fixed missing file "umd-tough-cookie.js“
- updated changeling
- incremented version for release
2016-12-07 17:21:03 +01:00
Sefa Ilkimen 8267a02c9d - updated change log
- incremented version for release
2016-12-07 16:48:02 +01:00
Sefa Ilkimen a1f678a886 fixed case-sensitive path for android source files 2016-12-07 16:20:17 +01:00
Sefa Ilkimen 69cf4d0939 - updated change log
- incremented version for release
2016-12-07 15:32:18 +01:00
Sefa Ilkimen d90cefcbaa fixed handling of multiple cookies 2016-12-07 15:29:54 +01:00
Sefa Ilkimen b3118d5ccd removed „String.prototype.startsWith“ call to be compatible with older web view versions 2016-12-06 16:05:48 +01:00
Sefa Ilkimen 6b0f23b2d1 fixed lodash exports 2016-12-06 11:52:38 +01:00
Sefa Ilkimen d0ece22302 Merge branch 'feature-cookie-handling' 2016-12-06 10:31:54 +01:00
Sefa Ilkimen a6a1bcaab1 updated readme file 2016-12-06 10:29:35 +01:00
Sefa Ilkimen 4afb375971 added function for clearing cookies 2016-12-05 18:25:14 +01:00
Sefa Ilkimen 20e5bd0ee9 added local storage store for cookies 2016-12-05 17:52:20 +01:00
Sefa Ilkimen e84d84c358 integrated „umd-tough-cookie“ for cookie handling 2016-12-05 13:19:26 +01:00
Sefa Ilkimen 955c590e42 - incremented version
- updated change log and readme
2016-11-14 15:43:18 +01:00
Sefa Ilkimen 0d627b7a0d Merge branch 'feature-put-delete-methods' 2016-11-14 15:13:55 +01:00
Sefa Ilkimen 8fc4c2b9cb minor changes for cleanup 2016-11-14 15:13:26 +01:00
Sefa Ilkimen a0edca1b1d updated README 2016-11-14 14:43:24 +01:00
Sefa Ilkimen d5b2cdaf60 implemented PUT and DELETE methods for Android and iOS 2016-11-14 13:56:54 +01:00
Sefa Ilkimen 0989de20ab renamed param serializer to data serializer 2016-11-14 00:47:24 +01:00
Sefa Ilkimen 050ed894d6 defined www interface for http methods PUT and DELETE 2016-11-14 00:18:16 +01:00
Sefa Ilkimen 4552e9c84b Merge branch 'feature-configurable-serializer' 2016-11-11 19:30:47 +01:00
Sefa Ilkimen c8df1ebd8b - implemented configurable serializer for Android
- cleaned up Android source structure
2016-11-11 19:24:49 +01:00
Sefa Ilkimen 50cda6a5af updated readme file 2016-11-11 02:22:53 +01:00
Sefa Ilkimen 4600fd0555 implemented configurable serializer for iOS 2016-11-11 01:33:29 +01:00
Sefa Ilkimen 46176500df fixed var name 2016-11-11 01:32:16 +01:00
Sefa Ilkimen 9f515d01d8 defined www interface for configurable parameter serializer 2016-11-10 18:46:30 +01:00
Andrew Stephan bf8ded59a2 1.2.0 2016-07-20 12:33:52 -04:00
Andrew StephanandGitHub c531ffaa44 Merge pull request #95 from wymsee/tls
Support for TLSv1.1 and TLSv1.2 for android 4.1 - 4.4
2016-07-20 12:33:41 -04:00
Andrew Stephan 0e4624f627 updated changelong 2016-07-20 12:05:11 -04:00
Andrew Stephan 9a65da55c9 only use custom factory for API Levels < 20 2016-07-20 11:55:49 -04:00
Andrew Stephan 4c26dd793e fixed var name 2016-07-18 15:56:11 -04:00
Andrew Stephan beae854526 updates to only allow tlsv1.1 and tlsv1.2 2016-07-18 15:42:30 -04:00
Andrew Stephan 9cd64b1d9e 1.1.0 2016-05-02 13:49:15 -04:00
Andrew Stephan d726998e5e Merge pull request #85 from wymsee/ios-errors
updated AFNetworking and edited requests to send back the body for errors
2016-05-02 13:49:00 -04:00
Andrew Stephan b6976bef18 README, CHANGELOG and version number updates 2016-05-02 13:48:48 -04:00
Andrew Stephan 60220a224b updated AFNetworking and edited requests to send back the body for errors 2016-04-29 14:19:29 -04:00
Andrew Stephan ba37200d75 updated readme with info on headers 2016-04-28 19:12:36 -04:00
Andrew Stephan 50d40e76eb Merge pull request #8 from SpiderOak/disable-encoding-get-urls
Disables encoding get() URLs by default (android)
2016-04-28 18:58:26 -04:00
Tommy-Carlos Williams 46517ae7f2 Disables encoding get() URLs by default
In our app this is leading to errors on URLs that are already properly encoded (they are being double-encoded... %20 -> %2520, etc)

Feel free to ignore or close this one if you need this functionality, but since `post()` URLs were *not* being encoded, I thought it might have just been a default that didn't affect you one way or the other.
2014-08-20 19:05:11 +10:00
62 changed files with 7287 additions and 697 deletions
+3 -1
View File
@@ -1,2 +1,4 @@
node_modules/**
tags tags
.zedstate .zedstate
/temp
+5
View File
@@ -0,0 +1,5 @@
tags
.zedstate
/scripts
/temp
/test
+43
View File
@@ -0,0 +1,43 @@
sudo: false
language: objective-c
os: osx
osx_image: xcode9.1
cache: false
addons:
sauce_connect:
username: silkimen
jwt: RZHC8x5ggrXdu1xzhhHmQDwege9s3putJXY1ZG8+MNMaBTLfLBWzFsHuR6Lvz+XnrAT/CTGG957kw6ikSaV6VEkGvtO91irZoJyShjPq2hBbn2CaEbo91Eq8iNYaRG+4FVMxoHa6xpF/HtvOLQdIkURc/lzLj/BOFMmtV/d3adLDcryQZuYB211iN4d6exGHMQe8uvJdkCy4ac85guhF8KmAELyaVa0rx0m6gNaszWU9BJ8Rn+4HJbJtfpQcU1bJN43Dx8forRU/Com53K+KFtDKPUdBHZnuENrZrQ+8RU59vdLrHwsCvP9elJFkcX9xk/r45oUGXhqVV3vMyaqTa9YUO772rhgKuAi4TqiaR51H58KWqynp7wOZwL5FqJs0KzL5rNDDIoKKrklnOidS4RAUKXCi1CUNXwDdOo4Kd96cYOIHqpwa7Beci8CtVlzd/49yE9/AXnZYVwp10uKZvJJdliAOHhVEAtCIp8PzHOOPYJsXvUcEU4ORWWWpusBAz6wFiLOL4d/CAHNj6wDFliRexBrv/Wunu5ifva4oVJWrtAtyGDtsX8kBkf8OcIdy/aPUIIBrbW1sapjPFymMGeL/KkSZRjEy7KjFZKZh9L7sJE56sq+IUremFbcyaX1E3rho6Cs3ongLaKhL9f9vz8EFs7//w8pNlNS9EUdOU68=
before_install:
- export LANG=en_US.UTF-8
- brew update
install:
- npm install
- brew install gradle
- wget http://dl.google.com/android/android-sdk_r24.4-macosx.zip
- tar -xvf android-sdk_r24.4-macosx.zip
- echo y | ./android-sdk-macosx/tools/android update sdk --no-ui --all --filter platform-tools
- echo y | ./android-sdk-macosx/tools/android update sdk --no-ui --all --filter build-tools-25.0.0
- echo y | ./android-sdk-macosx/tools/android update sdk --no-ui --all --filter android-25
- echo y | ./android-sdk-macosx/tools/android update sdk --no-ui --all --filter extra-android-support
- echo y | ./android-sdk-macosx/tools/android update sdk --no-ui --all --filter extra-android-m2repository
- echo y | ./android-sdk-macosx/tools/android update sdk --no-ui --all --filter extra-google-m2repository
- export ANDROID_HOME=./android-sdk-macosx
- export PATH=${PATH}:$ANDROID_HOME/tools:$ANDROID_HOME/platform-tools:$ANDROID_HOME/build-tools/23.0.2
script:
- travis_wait scripts/build-test-app.sh
- scripts/upload-artifact.sh
- scripts/test.sh --ios --emulator
after_success:
deploy:
notifications:
slack:
secure: lXE+2AgsxZU5G5dI91LkMAIgo8MAWfdM7DB5UOtn5LpuNln+2FmJo1gOI7tkdmLOqpXTGYnpI2VyQN3H4nOF21YhuouzD1Sh8n2wtQg1iTm353kuQpqiVhSBX8ZJ7Be1e1G8OsnxoYOxbs4Zo9qI40EruwkvqLCBHWM5MRGyd4M7EFWwb9Z29VZN0y1Nt5g/c3bT76kdKmF+JCLur2OeEKxAity7sIKgZekSqeIMwEVLSxXnda6Dbjc/cg0MJ0iDArkD7iu6fz/Fcrrxgm/pUxjcgvqze7Gy5i31mjEfspnrglWV1cshMd48BTDKCJ2AMmxH8O3GPSWE2txjIvGRWUve7iViNylvmQCVz3Eyf99+4EuuVGa+5PSodQ/CqODx/65EwtcN3PE1tNz2puKOK8nrOJcFkcbG8KTHKUlQtHCkjitbykUnj/hvhLK5/oWlQYVOLWWrHwdGUh8FI8aFPVGjRjWbHbhdayjEIqxwr1ns+6mYrP1EFNXbaeZxnLNC59XpJl1ifuezqYAk7YEiU5j4rtC7YKgyQ3ueb7anOHTJoTMyDn8mpZXgwuyhoBaeEYytQVgRyMtL6Y5cP98Jn2kv0+vdne3rkk9/JEBTo32HOjvoij6rsqEvXC0LhUDJSNadOVdHht0jjoN6zBH37HIE5/3zysLlPcAcHAS83ow=
+110 -1
View File
@@ -1,5 +1,114 @@
# Changelog # Changelog
## v1.6.2
- Change #29: removed "validateDomainName" (see info notice)
- Fixed #31: request fails throwing error on erroneous cookies
- Fixed #28: added support for content type "application/hal+json" on iOS (thanks ryandegruyter)
#### Important information
We've decided to remove the `validateDomainName()` method, because people were complaining that `acceptAllCerts(true)` is not behaving as expected. And also it's not a good idea to disable domain name validation while using valid certs, because it pretends having a secure connection, but it isn't.
You should either use valid certs with domain name validation enabled (safe for production use) or accept any certs without domain name validation (only for private dev environments). I strongly discourage using fake certs in public networks.
Therefore we are disabling domain name validation automatically, when you set `acceptAllCerts(true)`. So if you were using `validateDomainName()` function, you need to remove this function call for v1.6.2+.
## v1.6.1
- Fixed #23: PATCH method broken on android
## v1.6.0
- Feature #18: implemented PATCH method (thanks akhatri for android implementation)
- Feature #21: added redirection control (thanks to notsyncing and kesozjura)
- Fixed #16: cordova tries to run build script during plugin install
## v1.5.10
- Fixed #10: fix gzip decompression when request header accepts gzip compression (thanks to DayBr3ak)
- Fixed #13: fix angular integration for `setDataSerializer` (thanks to RangerRick)
- Added some missing documentation (thanks to RangerRick)
## v1.5.9
- Fixed case-sensitive folder name of Android source files
## v1.5.8
- Use the same error codes if a request timed out
## v1.5.7
- Fixed a bug in cookie handling (cookies containing an "Expires" string)
- Added setRequestTimeout function to set the timeout in seconds for all further requests
## v1.5.6
- All response header keys are converted to lowercase (iOS only)
## v1.5.5
- added a function to remove all cookies for a URL
## v1.5.4
- fixed an error if the response has no "headers" field
## v1.5.3
- handles cookies correctly on non-success response from server
- throws error when a callback function is missing
## v1.5.2
- fixed missing file "umd-tough-cookie.js“ (caused by missing file ".npmignore")
## v1.5.1
- fixed case-sensitive path name of android source files ("CordovaHTTP" --> "cordovahttp")
## v1.5.0
- added cookie handling
- cookies are persisted via web storage API
## v1.4.0
- forked from "cordova-plugin-http" v1.2.0 (see https://github.com/wymsee/cordova-HTTP)
- added configuration for data serializer
- added HTTP methods PUT and DELETE
# Previous changelog (cordova-plugin-http)
## v1.2.0
- Added support for TLSv1.1 and TLSv1.2 for android versions 4.1-4.4 (API levels 16-19)
### Potentially Breaking Changes that really shouldn't matter because you shouldn't be using SSLv3
- Dropped SSLv3 support for all API Levels < 20. It will now only work on API Levels 20-22.
## v1.1.0
- Fixed the body of errors not being returned in iOS
- Updated AFNetworking to 3.1.0
### Potentially Breaking Changes
- Disable encoding get() URLS in android (Thanks to devgeeks)
## v1.0.3
- Fixed version number in plugin.xml
## v1.0.2
- Fixed bug using useBasicAuth and setHeader from angular
## v1.0.1
- updated README
## v1.0.0 ## v1.0.0
- Added getBasicAuthHeader function - Added getBasicAuthHeader function
@@ -43,4 +152,4 @@
- Reports SSL Handshake errors rather than giving a generic error (Thanks to devgeeks) - Reports SSL Handshake errors rather than giving a generic error (Thanks to devgeeks)
- Exporting http as a module (Thanks to pvsaikrishna) - Exporting http as a module (Thanks to pvsaikrishna)
- Added Limitations section to readme (Thanks to cvillerm) - Added Limitations section to readme (Thanks to cvillerm)
- Fixed examples (Thanks to hideov) - Fixed examples (Thanks to hideov)
+2 -1
View File
@@ -1,5 +1,6 @@
The MIT License (MIT) The MIT License (MIT)
Copyright (c) 2017 Mobisys GmbH
Copyright (c) 2014 Wymsee, Inc Copyright (c) 2014 Wymsee, Inc
Permission is hereby granted, free of charge, to any person obtaining a copy Permission is hereby granted, free of charge, to any person obtaining a copy
@@ -18,4 +19,4 @@ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 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 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE. SOFTWARE.
+86 -63
View File
@@ -1,11 +1,18 @@
cordovaHTTP Cordova Advanced HTTP
================== =====================
[![npm version](https://badge.fury.io/js/cordova-plugin-advanced-http.svg)](https://badge.fury.io/js/cordova-plugin-advanced-http)
[![downloads/month](https://img.shields.io/npm/dm/cordova-plugin-advanced-http.svg)](https://www.npmjs.com/package/cordova-plugin-advanced-http)
[![MIT Licence](https://badges.frapsoft.com/os/mit/mit.png)](https://opensource.org/licenses/mit-license.php)
[![Build Status](https://travis-ci.org/silkimen/cordova-plugin-advanced-http.svg?branch=master)](https://travis-ci.org/silkimen/cordova-plugin-advanced-http)
Cordova / Phonegap plugin for communicating with HTTP servers. Supports iOS and Android. Cordova / Phonegap plugin for communicating with HTTP servers. Supports iOS and Android.
This is a fork of [Wymsee's Cordova-HTTP plugin](https://github.com/wymsee/cordova-HTTP).
## Advantages over Javascript requests ## Advantages over Javascript requests
- Background threading - all requests are done in a background thread. - Background threading - all requests are done in a background thread.
- Handling of HTTP code 401 - read more at [Issue CB-2415](https://issues.apache.org/jira/browse/CB-2415).
- SSL Pinning - read more at [LumberBlog](http://blog.lumberlabs.com/2012/04/why-app-developers-should-care-about.html). - SSL Pinning - read more at [LumberBlog](http://blog.lumberlabs.com/2012/04/why-app-developers-should-care-about.html).
## Updates ## Updates
@@ -17,26 +24,26 @@ Please check [CHANGELOG.md](CHANGELOG.md) for details about updating to a new ve
The plugin conforms to the Cordova plugin specification, it can be installed The plugin conforms to the Cordova plugin specification, it can be installed
using the Cordova / Phonegap command line interface. using the Cordova / Phonegap command line interface.
phonegap plugin add cordova-plugin-http phonegap plugin add cordova-plugin-advanced-http
cordova plugin add cordova-plugin-http cordova plugin add cordova-plugin-advanced-http
## Usage ## Usage
### AngularJS ### Without AngularJS
This plugin registers a global object located at `cordova.plugin.http`.
### With AngularJS
This plugin creates a cordovaHTTP service inside of a cordovaHTTP module. You must load the module when you create your app's module. This plugin creates a cordovaHTTP service inside of a cordovaHTTP module. You must load the module when you create your app's module.
var app = angular.module('myApp', ['ngRoute', 'ngAnimate', 'cordovaHTTP']); var app = angular.module('myApp', ['ngRoute', 'ngAnimate', 'cordovaHTTP']);
You can then inject the cordovaHTTP service into your controllers. The functions can then be used identically to the examples shown below except that instead of accepting success and failure callback functions, each function returns a promise. For more information on promises in AngularJS read the [AngularJS docs](http://docs.angularjs.org/api/ng/service/$q). For more info on promises in general check out this article on [html5rocks](http://www.html5rocks.com/en/tutorials/es6/promises/). Make sure that you load cordova.js or phonegap.js after AngularJS is loaded. You can then inject the cordovaHTTP service into your controllers. The functions can then be used identically to the examples shown below except that instead of accepting success and failure callback functions, each function returns a promise. For more information on promises in AngularJS read the [AngularJS docs](http://docs.angularjs.org/api/ng/service/$q). For more info on promises in general check out this article on [html5rocks](http://www.html5rocks.com/en/tutorials/es6/promises/). Make sure that you load cordova.js or phonegap.js after AngularJS is loaded.
### Not AngularJS
This plugin registers a `cordovaHTTP` global on window ## Synchronous Functions
## Sync Functions
### getBasicAuthHeader ### getBasicAuthHeader
This returns an object representing a basic HTTP Authorization header of the form `{'Authorization': 'Basic base64encodedusernameandpassword'}` This returns an object representing a basic HTTP Authorization header of the form `{'Authorization': 'Basic base64encodedusernameandpassword'}`
@@ -47,14 +54,39 @@ This returns an object representing a basic HTTP Authorization header of the for
This sets up all future requests to use Basic HTTP authentication with the given username and password. This sets up all future requests to use Basic HTTP authentication with the given username and password.
cordovaHTTP.useBasicAuth("user", "password"); cordovaHTTP.useBasicAuth("user", "password");
### setHeader ### setHeader
Set a header for all future requests. Takes a header and a value. Set a header for all future requests. Takes a header and a value.
cordovaHTTP.setHeader("Header", "Value"); cordovaHTTP.setHeader("Header", "Value");
## Async Functions ### disableRedirect
If set to `true`, it won't follow redirects automatically. This is a global setting.
cordovaHTTP.disableRedirect(true);
### setDataSerializer
Set the data serializer which will be used for all future POST and PUT requests. Takes a string representing the name of the serializer.
cordovaHTTP.setDataSerializer("urlencoded");
You can choose one of these two:
* `urlencoded`: send data as url encoded content in body (content type "application/x-www-form-urlencoded")
* `json`: send data as JSON encoded content in body (content type "application/json")
Caution: `urlencoded` does not support serializing deep structures whereas `json` does.
### setRequestTimeout
Set how long to wait for a request to respond, in seconds.
cordovaHTTP.setRequestTimeout(5.0);
### clearCookies
Clear the cookie store.
cordovaHTTP.clearCookies();
## Asynchronous Functions
These functions all take success and error callbacks as their last 2 arguments. These functions all take success and error callbacks as their last 2 arguments.
### enableSSLPinning ### enableSSLPinning
@@ -69,7 +101,7 @@ As an alternative, you can store your .cer files in the www/certificates folder.
}, function() { }, function() {
console.log('error :('); console.log('error :(');
}); });
### acceptAllCerts ### acceptAllCerts
Accept all SSL certificates. Or disable accepting all certificates. This defaults to false. Accept all SSL certificates. Or disable accepting all certificates. This defaults to false.
@@ -78,27 +110,29 @@ Accept all SSL certificates. Or disable accepting all certificates. This defau
}, function() { }, function() {
console.log('error :('); console.log('error :(');
}); });
### validateDomainName
Whether or not to validate the domain name in the certificate. This defaults to true.
cordovaHTTP.validateDomainName(false, function() { ### validateDomainName
console.log('success!'); This function was removed in v1.6.2. Domain name validation is disabled automatically when you enable "acceptAllCerts".
}, function() {
console.log('error :('); ### removeCookies
}); Remove all cookies associated with a given URL.
cordovaHTTP.removeCookies(url);
### post<a name="post"></a> ### post<a name="post"></a>
Execute a POST request. Takes a URL, parameters, and headers. Execute a POST request. Takes a URL, data, and headers.
#### success #### success
The success function receives a response object with 2 properties: status and data. Status is the HTTP response code and data is the response from the server as a string. Here's a quick example: The success function receives a response object with 3 properties: status, data, and headers. Status is the HTTP response code. Data is the response from the server as a string. Headers is an object with the headers. Here's a quick example:
{ {
status: 200, status: 200,
data: "{'id': 12, 'message': 'test'}" data: "{'id': 12, 'message': 'test'}",
headers: {
"Content-Length": "247"
}
} }
Most apis will return JSON meaning you'll want to parse the data like in the example below: Most apis will return JSON meaning you'll want to parse the data like in the example below:
cordovaHTTP.post("https://google.com/", { cordovaHTTP.post("https://google.com/", {
@@ -117,20 +151,23 @@ Most apis will return JSON meaning you'll want to parse the data like in the exa
}, function(response) { }, function(response) {
// prints 403 // prints 403
console.log(response.status); console.log(response.status);
//prints Permission denied //prints Permission denied
console.log(response.error); console.log(response.error);
}); });
#### failure #### failure
The error function receives a response object with 2 properties: status and error. Status is the HTTP response code. Error is the error response from the server as a string. Here's a quick example: The error function receives a response object with 3 properties: status, error and headers. Status is the HTTP response code. Error is the error response from the server as a string. Headers is an object with the headers. Here's a quick example:
{ {
status: 403, status: 403,
error: "Permission denied" error: "Permission denied",
headers: {
"Content-Length": "247"
}
} }
### get ### get
Execute a GET request. Takes a URL, parameters, and headers. See the [post](#post) documentation for details on what is returned on success and failure. Execute a GET request. Takes a URL, parameters, and headers. See the [post](#post) documentation for details on what is returned on success and failure.
@@ -142,7 +179,16 @@ Execute a GET request. Takes a URL, parameters, and headers. See the [post](#p
}, function(response) { }, function(response) {
console.error(response.error); console.error(response.error);
}); });
### put
Execute a PUT request. Takes a URL, data, and headers. See the [post](#post) documentation for details on what is returned on success and failure.
### delete
Execute a DELETE request. Takes a URL, parameters, and headers. See the [post](#post) documentation for details on what is returned on success and failure.
### head
Execute a HEAD request. Takes a URL, parameters, and headers. See the [post](#post) documentation for details on what is returned on success and failure.
### uploadFile ### uploadFile
Uploads a file saved on the device. Takes a URL, parameters, headers, filePath, and the name of the parameter to pass the file along as. See the [post](#post) documentation for details on what is returned on success and failure. Uploads a file saved on the device. Takes a URL, parameters, headers, filePath, and the name of the parameter to pass the file along as. See the [post](#post) documentation for details on what is returned on success and failure.
@@ -154,7 +200,7 @@ Uploads a file saved on the device. Takes a URL, parameters, headers, filePath,
}, function(response) { }, function(response) {
console.error(response.error); console.error(response.error);
}); });
### downloadFile ### downloadFile
Downloads a file and saves it to the device. Takes a URL, parameters, headers, and a filePath. See [post](#post) documentation for details on what is returned on failure. On success this function returns a cordova [FileEntry object](http://cordova.apache.org/docs/en/3.3.0/cordova_file_file.md.html#FileEntry). Downloads a file and saves it to the device. Takes a URL, parameters, headers, and a filePath. See [post](#post) documentation for details on what is returned on failure. On success this function returns a cordova [FileEntry object](http://cordova.apache.org/docs/en/3.3.0/cordova_file_file.md.html#FileEntry).
@@ -164,7 +210,7 @@ Downloads a file and saves it to the device. Takes a URL, parameters, headers,
}, { Authorization: "OAuth2: token" }, "file:///somepicture.jpg", function(entry) { }, { Authorization: "OAuth2: token" }, "file:///somepicture.jpg", function(entry) {
// prints the filename // prints the filename
console.log(entry.name); console.log(entry.name);
// prints the filePath // prints the filePath
console.log(entry.fullPath); console.log(entry.fullPath);
}, function(response) { }, function(response) {
@@ -174,32 +220,9 @@ Downloads a file and saves it to the device. Takes a URL, parameters, headers,
## Libraries ## Libraries
This plugin utilizes some awesome open source networking libraries. These are both MIT licensed: This plugin utilizes some awesome open source networking libraries. These are both MIT licensed:
- iOS - [AFNetworking](https://github.com/AFNetworking/AFNetworking) - iOS - [AFNetworking](https://github.com/AFNetworking/AFNetworking)
- Android - [http-request](https://github.com/kevinsawicki/http-request) - Android - [http-request](https://github.com/kevinsawicki/http-request)
We made a few modifications to http-request. They can be found in a separate repo here: https://github.com/wymsee/http-request We made a few modifications to both of them.
## Current Limitations
This plugin isn't equivalent to using XMLHttpRequest or Ajax calls in Javascript.
For instance, the following features are currently not supported:
- cookies support (a cookie set by a request isn't sent in subsequent requests)
- read content of error responses (only the HTTP status code and message are returned)
- read returned HTTP headers (e.g. in case security tokens are returned as headers)
Take this into account when using this plugin into your application.
## License
The MIT License
Copyright (c) 2014 Wymsee, Inc
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.
+36 -8
View File
@@ -1,9 +1,13 @@
{ {
"name": "cordova-plugin-http", "name": "cordova-plugin-advanced-http",
"version": "1.0.3", "version": "1.6.2",
"description": "Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning", "description": "Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning",
"scripts": {
"test": "./scripts/build-test-app.sh && ./scripts/test.sh --ios --emulator",
"release": "npm run test && ./scripts/release.sh"
},
"cordova": { "cordova": {
"id": "cordova-plugin-http", "id": "cordova-plugin-advanced-http",
"platforms": [ "platforms": [
"ios", "ios",
"android" "android"
@@ -11,25 +15,49 @@
}, },
"repository": { "repository": {
"type": "git", "type": "git",
"url": "git+https://github.com/wymsee/cordova-HTTP.git" "url": "git+https://github.com/silkimen/cordova-plugin-advanced-http.git"
}, },
"keywords": [ "keywords": [
"cordova", "cordova",
"device", "device",
"ecosystem:cordova", "ecosystem:cordova",
"cordova-ios", "cordova-ios",
"cordova-android" "cordova-android",
"ssl",
"tls"
], ],
"engines": [ "engines": [
{ {
"name": "cordova", "name": "cordova",
"version": ">=3.0.0" "version": ">=4.0.0"
} }
], ],
"author": "Wymsee", "author": "Wymsee",
"contributors": [
"devgeeks",
"EddyVerbruggen",
"mbektchiev",
"denisbabineau",
"andrey-tsaplin",
"pvsaikrishna",
"cvillerm",
"hideov",
"Mobisys"
],
"license": "MIT", "license": "MIT",
"bugs": { "bugs": {
"url": "https://github.com/wymsee/cordova-HTTP/issues" "url": "https://github.com/silkimen/cordova-plugin-advanced-http/issues"
}, },
"homepage": "https://github.com/wymsee/cordova-HTTP#readme" "homepage": "https://github.com/silkimen/cordova-plugin-advanced-http#readme",
"devDependencies": {
"chai": "4.1.2",
"chai-as-promised": "7.1.1",
"colors": "1.1.2",
"cordova": "7.0.1",
"mocha": "4.0.0",
"mz": "2.7.0",
"umd-tough-cookie": "2.3.2",
"wd": "1.4.1",
"xml2js": "0.4.19"
}
} }
+66 -81
View File
@@ -1,82 +1,67 @@
<?xml version="1.0" encoding="UTF-8"?> <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<plugin xmlns="http://www.phonegap.com/ns/plugins/1.0" <plugin xmlns="http://www.phonegap.com/ns/plugins/1.0" xmlns:android="http://schemas.android.com/apk/res/android" id="cordova-plugin-advanced-http" version="1.6.2">
xmlns:android="http://schemas.android.com/apk/res/android" <name>Advanced HTTP plugin</name>
id="cordova-plugin-http" <description>
version="1.0.3">
<name>SSL Pinning</name>
<description>
Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning
</description> </description>
<engines>
<engines> <engine name="cordova" version=">=4.0.0"/>
<engine name="cordova" version=">=3.0.0" /> </engines>
</engines> <dependency id="cordova-plugin-file" version=">=2.0.0"/>
<js-module src="www/lodash.js" name="lodash"/>
<dependency id="cordova-plugin-file" version=">=2.0.0" /> <js-module src="www/umd-tough-cookie.js" name="tough-cookie"/>
<js-module src="www/local-storage-store.js" name="local-storage-store"/>
<js-module src="www/cordovaHTTP.js" name="CordovaHttpPlugin"> <js-module src="www/cookie-handler.js" name="cookie-handler"/>
<clobbers target="CordovaHttpPlugin" /> <js-module src="www/angular-integration.js" name="angular-integration"/>
</js-module> <js-module src="www/advanced-http.js" name="http">
<clobbers target="cordova.plugin.http"/>
<!-- ios --> </js-module>
<platform name="ios"> <platform name="ios">
<config-file target="config.xml" parent="/*"> <config-file target="config.xml" parent="/*">
<feature name="CordovaHttpPlugin"> <feature name="CordovaHttpPlugin">
<param name="ios-package" value="CordovaHttpPlugin"/> <param name="ios-package" value="CordovaHttpPlugin"/>
</feature> </feature>
</config-file> </config-file>
<header-file src="src/ios/CordovaHttpPlugin.h"/>
<header-file src="src/ios/CordovaHttpPlugin.h" /> <header-file src="src/ios/TextResponseSerializer.h"/>
<source-file src="src/ios/CordovaHttpPlugin.m" /> <header-file src="src/ios/AFNetworking/AFHTTPSessionManager.h"/>
<header-file src="src/ios/AFNetworking/AFNetworking.h"/>
<header-file src="src/ios/TextResponseSerializer.h" /> <header-file src="src/ios/AFNetworking/AFNetworkReachabilityManager.h"/>
<source-file src="src/ios/TextResponseSerializer.m" /> <header-file src="src/ios/AFNetworking/AFSecurityPolicy.h"/>
<header-file src="src/ios/AFNetworking/AFURLRequestSerialization.h"/>
<header-file src="src/ios/AFNetworking/AFHTTPSessionManager.h" /> <header-file src="src/ios/AFNetworking/AFURLResponseSerialization.h"/>
<source-file src="src/ios/AFNetworking/AFHTTPSessionManager.m" /> <header-file src="src/ios/AFNetworking/AFURLSessionManager.h"/>
<source-file src="src/ios/CordovaHttpPlugin.m"/>
<header-file src="src/ios/AFNetworking/AFNetworking.h" /> <source-file src="src/ios/TextResponseSerializer.m"/>
<source-file src="src/ios/AFNetworking/AFHTTPSessionManager.m"/>
<header-file src="src/ios/AFNetworking/AFNetworkReachabilityManager.h" /> <source-file src="src/ios/AFNetworking/AFNetworkReachabilityManager.m"/>
<source-file src="src/ios/AFNetworking/AFNetworkReachabilityManager.m" /> <source-file src="src/ios/AFNetworking/AFSecurityPolicy.m"/>
<source-file src="src/ios/AFNetworking/AFURLRequestSerialization.m"/>
<header-file src="src/ios/AFNetworking/AFSecurityPolicy.h" /> <source-file src="src/ios/AFNetworking/AFURLResponseSerialization.m"/>
<source-file src="src/ios/AFNetworking/AFSecurityPolicy.m" /> <source-file src="src/ios/AFNetworking/AFURLSessionManager.m"/>
<framework src="Security.framework"/>
<header-file src="src/ios/AFNetworking/AFURLRequestSerialization.h" /> <framework src="SystemConfiguration.framework"/>
<source-file src="src/ios/AFNetworking/AFURLRequestSerialization.m" /> </platform>
<platform name="android">
<header-file src="src/ios/AFNetworking/AFURLResponseSerialization.h" /> <config-file target="res/xml/config.xml" parent="/*">
<source-file src="src/ios/AFNetworking/AFURLResponseSerialization.m" /> <feature name="CordovaHttpPlugin">
<param name="android-package" value="com.synconset.cordovahttp.CordovaHttpPlugin"/>
<header-file src="src/ios/AFNetworking/AFURLSessionManager.h" /> </feature>
<source-file src="src/ios/AFNetworking/AFURLSessionManager.m" /> </config-file>
<config-file target="AndroidManifest.xml" parent="/manifest">
<framework src="Security.framework" /> <uses-permission android:name="android.permission.INTERNET"/>
<framework src="SystemConfiguration.framework" /> </config-file>
</platform> <source-file src="src/android/com/github/kevinsawicki/http/HttpRequest.java" target-dir="src/com/github/kevinsawicki/http"/>
<source-file src="src/android/com/github/kevinsawicki/http/TLSSocketFactory.java" target-dir="src/com/github/kevinsawicki/http"/>
<!--android --> <source-file src="src/android/com/synconset/cordovahttp/CordovaHttp.java" target-dir="src/com/synconset/cordovahttp"/>
<platform name="android"> <source-file src="src/android/com/synconset/cordovahttp/CordovaHttpDelete.java" target-dir="src/com/synconset/cordovahttp"/>
<config-file target="res/xml/config.xml" parent="/*"> <source-file src="src/android/com/synconset/cordovahttp/CordovaHttpDownload.java" target-dir="src/com/synconset/cordovahttp"/>
<feature name="CordovaHttpPlugin"> <source-file src="src/android/com/synconset/cordovahttp/CordovaHttpGet.java" target-dir="src/com/synconset/cordovahttp"/>
<param name="android-package" value="com.synconset.CordovaHttpPlugin"/> <source-file src="src/android/com/synconset/cordovahttp/CordovaHttpHead.java" target-dir="src/com/synconset/cordovahttp"/>
</feature> <source-file src="src/android/com/synconset/cordovahttp/CordovaHttpPlugin.java" target-dir="src/com/synconset/cordovahttp"/>
</config-file> <source-file src="src/android/com/synconset/cordovahttp/CordovaHttpPost.java" target-dir="src/com/synconset/cordovahttp"/>
<source-file src="src/android/com/synconset/cordovahttp/CordovaHttpPut.java" target-dir="src/com/synconset/cordovahttp"/>
<config-file target="AndroidManifest.xml" parent="/manifest"> <source-file src="src/android/com/synconset/cordovahttp/CordovaHttpPatch.java" target-dir="src/com/synconset/cordovahttp"/>
<uses-permission android:name="android.permission.INTERNET" /> <source-file src="src/android/com/synconset/cordovahttp/CordovaHttpUpload.java" target-dir="src/com/synconset/cordovahttp"/>
</config-file> </platform>
</plugin>
<source-file src="src/android/com/synconset/CordovaHTTP/CordovaHttp.java" target-dir="src/com/synconset" />
<source-file src="src/android/com/synconset/CordovaHTTP/CordovaHttpGet.java" target-dir="src/com/synconset" />
<source-file src="src/android/com/synconset/CordovaHTTP/CordovaHttpPost.java" target-dir="src/com/synconset" />
<source-file src="src/android/com/synconset/CordovaHTTP/CordovaHttpHead.java" target-dir="src/com/synconset" />
<source-file src="src/android/com/synconset/CordovaHTTP/CordovaHttpUpload.java" target-dir="src/com/synconset" />
<source-file src="src/android/com/synconset/CordovaHTTP/CordovaHttpDownload.java" target-dir="src/com/synconset" />
<source-file src="src/android/com/synconset/CordovaHTTP/CordovaHttpPlugin.java" target-dir="src/com/synconset" />
<source-file src="src/android/com/synconset/CordovaHTTP/HttpRequest.java" target-dir="src/com/github/kevinsawicki/http" />
</platform>
</plugin>
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -e
PLATFORM=$([[ "${@#--android}" = "$@" ]] && echo "ios" || echo "android")
TARGET=$([[ "${@#--device}" = "$@" ]] && echo "emulator" || echo "device")
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/..
CDV=$ROOT/node_modules/.bin/cordova
rm -rf $ROOT/temp
mkdir $ROOT/temp
cp -r $ROOT/test/app-template/ $ROOT/temp/
cp $ROOT/test/test-definitions.js $ROOT/temp/www/js/
cd $ROOT/temp
$CDV prepare
$CDV plugins add $ROOT
$CDV build $PLATFORM --$TARGET
+13
View File
@@ -0,0 +1,13 @@
#!/usr/bin/env bash
set -e
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/..
pushd $ROOT
VERSION=$(node -e "console.log(require('./package.json').version)")
./scripts/update-tough-cookie.sh
node ./scripts/update-plugin-xml.js $VERSION
git commit -a -m "release v$VERSION"
git tag "v$VERSION"
npm publish
popd
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -e
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/..
pushd $ROOT
./node_modules/.bin/mocha ./test/mocha-specs/test.js "$@"
popd
+31
View File
@@ -0,0 +1,31 @@
const args = process.argv.slice(2);
const fs = require('mz/fs');
const path = require('path');
const xml2js = require('xml2js');
const xmlPath = path.join(__dirname, '..', 'plugin.xml');
const parse = xml => new Promise((resolve, reject) => {
const parser = new xml2js.Parser();
parser.parseString(xml, (error, result) => {
if (error) {
reject(error);
} else {
resolve(result);
}
});
});
const stringify = obj => {
const builder = new xml2js.Builder();
return builder.buildObject(obj);
};
fs.readFile(xmlPath, 'utf-8')
.then(xml => parse(xml))
.then(parsed => {
parsed.plugin.$.version = args[0];
return fs.writeFile(xmlPath, stringify(parsed));
});
+8
View File
@@ -0,0 +1,8 @@
#!/usr/bin/env bash
set -e
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/..
cd $ROOT
npm i
cp node_modules/umd-tough-cookie/lib/umd-tough-cookie.js www/umd-tough-cookie.js
+16
View File
@@ -0,0 +1,16 @@
#!/usr/bin/env bash
set -e
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/..
TEMP=$ROOT/temp
rm -rf $TEMP/HttpDemo.app.zip
pushd $TEMP/platforms/ios/build/emulator
zip -r $TEMP/HttpDemo.app.zip ./HttpDemo.app
popd
curl -u $SAUCE_USERNAME:$SAUCE_ACCESS_KEY \
-X POST \
-H "Content-Type: application/octet-stream" \
https://saucelabs.com/rest/v1/storage/$SAUCE_USERNAME/HttpDemo.app.zip?overwrite=true \
--data-binary @$TEMP/HttpDemo.app.zip
@@ -236,6 +236,11 @@ public class HttpRequest {
*/ */
public static final String METHOD_POST = "POST"; public static final String METHOD_POST = "POST";
/**
* 'PATCH' request method
*/
public static final String METHOD_PATCH = "PATCH";
/** /**
* 'PUT' request method * 'PUT' request method
*/ */
@@ -259,11 +264,11 @@ public class HttpRequest {
private static final String CRLF = "\r\n"; private static final String CRLF = "\r\n";
private static final String[] EMPTY_STRINGS = new String[0]; private static final String[] EMPTY_STRINGS = new String[0];
private static SSLSocketFactory PINNED_FACTORY; private static SSLSocketFactory PINNED_FACTORY;
private static SSLSocketFactory TRUSTED_FACTORY; private static SSLSocketFactory TRUSTED_FACTORY;
private static ArrayList<Certificate> PINNED_CERTS; private static ArrayList<Certificate> PINNED_CERTS;
private static HostnameVerifier TRUSTED_VERIFIER; private static HostnameVerifier TRUSTED_VERIFIER;
@@ -274,7 +279,7 @@ public class HttpRequest {
else else
return CHARSET_UTF8; return CHARSET_UTF8;
} }
private static SSLSocketFactory getPinnedFactory() private static SSLSocketFactory getPinnedFactory()
throws HttpRequestException { throws HttpRequestException {
if (PINNED_FACTORY != null) { if (PINNED_FACTORY != null) {
@@ -305,7 +310,12 @@ public class HttpRequest {
try { try {
SSLContext context = SSLContext.getInstance("TLS"); SSLContext context = SSLContext.getInstance("TLS");
context.init(null, trustAllCerts, new SecureRandom()); context.init(null, trustAllCerts, new SecureRandom());
TRUSTED_FACTORY = context.getSocketFactory();
if (android.os.Build.VERSION.SDK_INT < 20) {
TRUSTED_FACTORY = new TLSSocketFactory(context);
} else {
TRUSTED_FACTORY = context.getSocketFactory();
}
} catch (GeneralSecurityException e) { } catch (GeneralSecurityException e) {
IOException ioException = new IOException( IOException ioException = new IOException(
"Security exception configuring SSL context"); "Security exception configuring SSL context");
@@ -424,8 +434,8 @@ public class HttpRequest {
else else
CONNECTION_FACTORY = connectionFactory; CONNECTION_FACTORY = connectionFactory;
} }
/** /**
* Add a certificate to test against when using ssl pinning. * Add a certificate to test against when using ssl pinning.
* *
@@ -436,28 +446,33 @@ public class HttpRequest {
*/ */
public static void addCert(Certificate ca) throws GeneralSecurityException, IOException { public static void addCert(Certificate ca) throws GeneralSecurityException, IOException {
if (PINNED_CERTS == null) { if (PINNED_CERTS == null) {
PINNED_CERTS = new ArrayList<Certificate>(); PINNED_CERTS = new ArrayList<Certificate>();
} }
PINNED_CERTS.add(ca); PINNED_CERTS.add(ca);
String keyStoreType = KeyStore.getDefaultType(); String keyStoreType = KeyStore.getDefaultType();
KeyStore keyStore = KeyStore.getInstance(keyStoreType); KeyStore keyStore = KeyStore.getInstance(keyStoreType);
keyStore.load(null, null); keyStore.load(null, null);
for (int i = 0; i < PINNED_CERTS.size(); i++) { for (int i = 0; i < PINNED_CERTS.size(); i++) {
keyStore.setCertificateEntry("CA" + i, PINNED_CERTS.get(i)); keyStore.setCertificateEntry("CA" + i, PINNED_CERTS.get(i));
} }
// Create a TrustManager that trusts the CAs in our KeyStore // Create a TrustManager that trusts the CAs in our KeyStore
String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm(); String tmfAlgorithm = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm); TrustManagerFactory tmf = TrustManagerFactory.getInstance(tmfAlgorithm);
tmf.init(keyStore); tmf.init(keyStore);
// Create an SSLContext that uses our TrustManager // Create an SSLContext that uses our TrustManager
SSLContext sslContext = SSLContext.getInstance("TLS"); SSLContext sslContext = SSLContext.getInstance("TLS");
sslContext.init(null, tmf.getTrustManagers(), null); sslContext.init(null, tmf.getTrustManagers(), null);
PINNED_FACTORY = sslContext.getSocketFactory();
if (android.os.Build.VERSION.SDK_INT < 20) {
PINNED_FACTORY = new TLSSocketFactory(sslContext);
} else {
PINNED_FACTORY = sslContext.getSocketFactory();
}
} }
/** /**
* Add a certificate to test against when using ssl pinning. * Add a certificate to test against when using ssl pinning.
* *
@@ -1166,6 +1181,70 @@ public class HttpRequest {
return post(encode ? encode(url) : url); return post(encode ? encode(url) : url);
} }
/**
* Start a 'PATCH' request to the given URL
*
* @param url
* @return request
* @throws HttpRequestException
*/
public static HttpRequest patch(final CharSequence url)
throws HttpRequestException {
return new HttpRequest(url, METHOD_PATCH);
}
/**
* Start a 'PATCH' request to the given URL
*
* @param url
* @return request
* @throws HttpRequestException
*/
public static HttpRequest patch(final URL url) throws HttpRequestException {
return new HttpRequest(url, METHOD_PATCH);
}
/**
* Start a 'PATCH' request to the given URL along with the query params
*
* @param baseUrl
* @param params
* the query parameters to include as part of the baseUrl
* @param encode
* true to encode the full URL
*
* @see #append(CharSequence, Map)
* @see #encode(CharSequence)
*
* @return request
*/
public static HttpRequest patch(final CharSequence baseUrl,
final Map<?, ?> params, final boolean encode) {
String url = append(baseUrl, params);
return patch(encode ? encode(url) : url);
}
/**
* Start a 'PATCH' request to the given URL along with the query params
*
* @param baseUrl
* @param encode
* true to encode the full URL
* @param params
* the name/value query parameter pairs to include as part of the
* baseUrl
*
* @see #append(CharSequence, Object...)
* @see #encode(CharSequence)
*
* @return request
*/
public static HttpRequest patch(final CharSequence baseUrl,
final boolean encode, final Object... params) {
String url = append(baseUrl, params);
return patch(encode ? encode(url) : url);
}
/** /**
* Start a 'PUT' request to the given URL * Start a 'PUT' request to the given URL
* *
@@ -3246,7 +3325,7 @@ public class HttpRequest {
form(entry, charset); form(entry, charset);
return this; return this;
} }
/** /**
* Configure HTTPS connection to trust only certain certificates * Configure HTTPS connection to trust only certain certificates
* <p> * <p>
@@ -3265,7 +3344,7 @@ public class HttpRequest {
} }
return this; return this;
} }
/** /**
* Configure HTTPS connection to trust all certificates * Configure HTTPS connection to trust all certificates
* <p> * <p>
@@ -0,0 +1,61 @@
package com.github.kevinsawicki.http;
import java.io.IOException;
import java.net.InetAddress;
import java.net.Socket;
import java.net.UnknownHostException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.SSLSocket;
import javax.net.ssl.SSLSocketFactory;
public class TLSSocketFactory extends SSLSocketFactory {
private SSLSocketFactory internalSSLSocketFactory;
public TLSSocketFactory(SSLContext context) {
internalSSLSocketFactory = context.getSocketFactory();
}
@Override
public String[] getDefaultCipherSuites() {
return internalSSLSocketFactory.getDefaultCipherSuites();
}
@Override
public String[] getSupportedCipherSuites() {
return internalSSLSocketFactory.getSupportedCipherSuites();
}
@Override
public Socket createSocket(Socket s, String host, int port, boolean autoClose) throws IOException {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(s, host, port, autoClose));
}
@Override
public Socket createSocket(String host, int port) throws IOException, UnknownHostException {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port));
}
@Override
public Socket createSocket(String host, int port, InetAddress localHost, int localPort) throws IOException, UnknownHostException {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port, localHost, localPort));
}
@Override
public Socket createSocket(InetAddress host, int port) throws IOException {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(host, port));
}
@Override
public Socket createSocket(InetAddress address, int port, InetAddress localAddress, int localPort) throws IOException {
return enableTLSOnSocket(internalSSLSocketFactory.createSocket(address, port, localAddress, localPort));
}
private Socket enableTLSOnSocket(Socket socket) {
if(socket != null && (socket instanceof SSLSocket)) {
((SSLSocket)socket).setEnabledProtocols(new String[] {"TLSv1", "TLSv1.1", "TLSv1.2"});
}
return socket;
}
}
@@ -1,63 +1,64 @@
/** /**
* A HTTP plugin for Cordova / Phonegap * A HTTP plugin for Cordova / Phonegap
*/ */
package com.synconset; package com.synconset.cordovahttp;
import org.apache.cordova.CallbackContext; import org.apache.cordova.CallbackContext;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.BufferedReader;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLConnection;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.HostnameVerifier;
import java.util.Iterator; import java.util.Iterator;
import android.util.Log; import android.text.TextUtils;
import com.github.kevinsawicki.http.HttpRequest; import com.github.kevinsawicki.http.HttpRequest;
public abstract class CordovaHttp { abstract class CordovaHttp {
protected static final String TAG = "CordovaHTTP"; protected static final String TAG = "CordovaHTTP";
protected static final String CHARSET = "UTF-8"; protected static final String CHARSET = "UTF-8";
private static AtomicBoolean sslPinning = new AtomicBoolean(false); private static AtomicBoolean sslPinning = new AtomicBoolean(false);
private static AtomicBoolean acceptAllCerts = new AtomicBoolean(false); private static AtomicBoolean acceptAllCerts = new AtomicBoolean(false);
private static AtomicBoolean validateDomainName = new AtomicBoolean(true); private static AtomicBoolean validateDomainName = new AtomicBoolean(true);
private static AtomicBoolean disableRedirect = new AtomicBoolean(false);
private String urlString; private String urlString;
private Map<?, ?> params; private JSONObject params;
private Map<String, String> headers; private String serializerName;
private JSONObject headers;
private int timeoutInMilliseconds;
private CallbackContext callbackContext; private CallbackContext callbackContext;
public CordovaHttp(String urlString, Map<?, ?> params, Map<String, String> headers, CallbackContext callbackContext) { public CordovaHttp(String urlString, JSONObject params, JSONObject headers, int timeout, CallbackContext callbackContext) {
this.urlString = urlString; this.urlString = urlString;
this.params = params; this.params = params;
this.serializerName = "default";
this.headers = headers; this.headers = headers;
this.timeoutInMilliseconds = timeout;
this.callbackContext = callbackContext; this.callbackContext = callbackContext;
} }
public CordovaHttp(String urlString, JSONObject params, String serializerName, JSONObject headers, int timeout, CallbackContext callbackContext) {
this.urlString = urlString;
this.params = params;
this.serializerName = serializerName;
this.headers = headers;
this.timeoutInMilliseconds = timeout;
this.callbackContext = callbackContext;
}
public static void enableSSLPinning(boolean enable) { public static void enableSSLPinning(boolean enable) {
sslPinning.set(enable); sslPinning.set(enable);
if (enable) { if (enable) {
acceptAllCerts.set(false); acceptAllCerts.set(false);
} }
} }
public static void acceptAllCerts(boolean accept) { public static void acceptAllCerts(boolean accept) {
acceptAllCerts.set(accept); acceptAllCerts.set(accept);
if (accept) { if (accept) {
@@ -69,22 +70,42 @@ public abstract class CordovaHttp {
validateDomainName.set(accept); validateDomainName.set(accept);
} }
public static void disableRedirect(boolean disable) {
disableRedirect.set(disable);
}
protected String getUrlString() { protected String getUrlString() {
return this.urlString; return this.urlString;
} }
protected Map<?, ?> getParams() { protected JSONObject getParamsObject() {
return this.params; return this.params;
} }
protected Map<String, String> getHeaders() { protected String getSerializerName() {
return this.serializerName;
}
protected HashMap<String, Object> getParamsMap() throws JSONException {
return this.getMapFromJSONObject(this.params);
}
protected JSONObject getHeadersObject() {
return this.headers; return this.headers;
} }
protected HashMap<String, String> getHeadersMap() throws JSONException {
return this.getStringMapFromJSONObject(this.headers);
}
protected int getRequestTimeout() {
return this.timeoutInMilliseconds;
}
protected CallbackContext getCallbackContext() { protected CallbackContext getCallbackContext() {
return this.callbackContext; return this.callbackContext;
} }
protected HttpRequest setupSecurity(HttpRequest request) { protected HttpRequest setupSecurity(HttpRequest request) {
if (acceptAllCerts.get()) { if (acceptAllCerts.get()) {
request.trustAllCerts(); request.trustAllCerts();
@@ -97,7 +118,14 @@ public abstract class CordovaHttp {
} }
return request; return request;
} }
protected HttpRequest setupRedirect(HttpRequest request) {
if (disableRedirect.get()) {
request.followRedirects(false);
}
return request;
}
protected void respondWithError(int status, String msg) { protected void respondWithError(int status, String msg) {
try { try {
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
@@ -108,21 +136,46 @@ public abstract class CordovaHttp {
this.callbackContext.error(msg); this.callbackContext.error(msg);
} }
} }
protected void respondWithError(String msg) { protected void respondWithError(String msg) {
this.respondWithError(500, msg); this.respondWithError(500, msg);
} }
protected void addResponseHeaders(HttpRequest request, JSONObject response) throws JSONException { protected void addResponseHeaders(HttpRequest request, JSONObject response) throws JSONException {
Map<String, List<String>> headers = request.headers(); Map<String, List<String>> headers = request.headers();
Map<String, String> parsed_headers = new HashMap<String, String>(); Map<String, String> filteredHeaders = new HashMap<String, String>();
for (Map.Entry<String, List<String>> entry : headers.entrySet()) { for (Map.Entry<String, List<String>> entry : headers.entrySet()) {
String key = entry.getKey(); String key = entry.getKey();
List<String> value = entry.getValue(); List<String> value = entry.getValue();
if ((key != null) && (!value.isEmpty())) { if ((key != null) && (!value.isEmpty())) {
parsed_headers.put(key, value.get(0)); filteredHeaders.put(key, TextUtils.join(", ", value));
} }
} }
response.put("headers", new JSONObject(parsed_headers));
response.put("headers", new JSONObject(filteredHeaders));
}
protected HashMap<String, String> getStringMapFromJSONObject(JSONObject object) throws JSONException {
HashMap<String, String> map = new HashMap<String, String>();
Iterator<?> i = object.keys();
while (i.hasNext()) {
String key = (String)i.next();
map.put(key, object.getString(key));
}
return map;
}
protected HashMap<String, Object> getMapFromJSONObject(JSONObject object) throws JSONException {
HashMap<String, Object> map = new HashMap<String, Object>();
Iterator<?> i = object.keys();
while(i.hasNext()) {
String key = (String)i.next();
map.put(key, object.get(key));
}
return map;
} }
} }
@@ -1,40 +1,45 @@
/** /**
* A HTTP plugin for Cordova / Phonegap * A HTTP plugin for Cordova / Phonegap
*/ */
package com.synconset; package com.synconset.cordovahttp;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Map;
import org.apache.cordova.CallbackContext;
import org.json.JSONException;
import org.json.JSONObject;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
import android.util.Log; import org.apache.cordova.CallbackContext;
import org.json.JSONException;
import org.json.JSONObject;
import com.github.kevinsawicki.http.HttpRequest; import com.github.kevinsawicki.http.HttpRequest;
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException; import com.github.kevinsawicki.http.HttpRequest.HttpRequestException;
public class CordovaHttpPost extends CordovaHttp implements Runnable { class CordovaHttpDelete extends CordovaHttp implements Runnable {
public CordovaHttpPost(String urlString, Map<?, ?> params, Map<String, String> headers, CallbackContext callbackContext) { public CordovaHttpDelete(String urlString, JSONObject data, JSONObject headers, int timeout, CallbackContext callbackContext) {
super(urlString, params, headers, callbackContext); super(urlString, data, headers, timeout, callbackContext);
} }
@Override @Override
public void run() { public void run() {
try { try {
HttpRequest request = HttpRequest.post(this.getUrlString()); HttpRequest request = HttpRequest.delete(this.getUrlString(), this.getParamsMap(), false);
request.readTimeout(this.getRequestTimeout());
this.setupRedirect(request);
this.setupSecurity(request); this.setupSecurity(request);
request.acceptCharset(CHARSET); request.acceptCharset(CHARSET);
request.headers(this.getHeaders()); request.headers(this.getHeadersMap());
request.form(this.getParams()); request.uncompress(true);
int code = request.code(); int code = request.code();
String body = request.body(CHARSET); String body = request.body(CHARSET);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
this.addResponseHeaders(request, response); this.addResponseHeaders(request, response);
response.put("status", code); response.put("status", code);
if (code >= 200 && code < 300) { if (code >= 200 && code < 300) {
response.put("data", body); response.put("data", body);
this.getCallbackContext().success(response); this.getCallbackContext().success(response);
@@ -44,9 +49,11 @@ public class CordovaHttpPost extends CordovaHttp implements Runnable {
} }
} catch (JSONException e) { } catch (JSONException e) {
this.respondWithError("There was an error generating the response"); this.respondWithError("There was an error generating the response");
} catch (HttpRequestException e) { } catch (HttpRequestException e) {
if (e.getCause() instanceof UnknownHostException) { if (e.getCause() instanceof UnknownHostException) {
this.respondWithError(0, "The host could not be resolved"); this.respondWithError(0, "The host could not be resolved");
} else if (e.getCause() instanceof SocketTimeoutException) {
this.respondWithError(1, "The request timed out");
} else if (e.getCause() instanceof SSLHandshakeException) { } else if (e.getCause() instanceof SSLHandshakeException) {
this.respondWithError("SSL handshake failed"); this.respondWithError("SSL handshake failed");
} else { } else {
@@ -1,18 +1,16 @@
/** /**
* A HTTP plugin for Cordova / Phonegap * A HTTP plugin for Cordova / Phonegap
*/ */
package com.synconset; package com.synconset.cordovahttp;
import android.util.Log;
import com.github.kevinsawicki.http.HttpRequest; import com.github.kevinsawicki.http.HttpRequest;
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException; import com.github.kevinsawicki.http.HttpRequest.HttpRequestException;
import java.io.File; import java.io.File;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Map;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
@@ -22,23 +20,27 @@ import org.apache.cordova.file.FileUtils;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
public class CordovaHttpDownload extends CordovaHttp implements Runnable { class CordovaHttpDownload extends CordovaHttp implements Runnable {
private String filePath; private String filePath;
public CordovaHttpDownload(String urlString, Map<?, ?> params, Map<String, String> headers, CallbackContext callbackContext, String filePath) { public CordovaHttpDownload(String urlString, JSONObject params, JSONObject headers, String filePath, int timeout, CallbackContext callbackContext) {
super(urlString, params, headers, callbackContext); super(urlString, params, headers, timeout, callbackContext);
this.filePath = filePath; this.filePath = filePath;
} }
@Override @Override
public void run() { public void run() {
try { try {
HttpRequest request = HttpRequest.get(this.getUrlString(), this.getParams(), true); HttpRequest request = HttpRequest.get(this.getUrlString(), this.getParamsMap(), true);
request.readTimeout(this.getRequestTimeout());
this.setupRedirect(request);
this.setupSecurity(request); this.setupSecurity(request);
request.acceptCharset(CHARSET); request.acceptCharset(CHARSET);
request.headers(this.getHeaders()); request.headers(this.getHeadersMap());
request.uncompress(true);
int code = request.code(); int code = request.code();
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
this.addResponseHeaders(request, response); this.addResponseHeaders(request, response);
response.put("status", code); response.put("status", code);
@@ -60,6 +62,8 @@ public class CordovaHttpDownload extends CordovaHttp implements Runnable {
} catch (HttpRequestException e) { } catch (HttpRequestException e) {
if (e.getCause() instanceof UnknownHostException) { if (e.getCause() instanceof UnknownHostException) {
this.respondWithError(0, "The host could not be resolved"); this.respondWithError(0, "The host could not be resolved");
} else if (e.getCause() instanceof SocketTimeoutException) {
this.respondWithError(1, "The request timed out");
} else if (e.getCause() instanceof SSLHandshakeException) { } else if (e.getCause() instanceof SSLHandshakeException) {
this.respondWithError("SSL handshake failed"); this.respondWithError("SSL handshake failed");
} else { } else {
@@ -1,47 +1,45 @@
/** /**
* A HTTP plugin for Cordova / Phonegap * A HTTP plugin for Cordova / Phonegap
*/ */
package com.synconset; package com.synconset.cordovahttp;
import java.io.IOException; import java.net.SocketTimeoutException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
import org.apache.cordova.CallbackContext; import org.apache.cordova.CallbackContext;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.util.Log;
import com.github.kevinsawicki.http.HttpRequest; import com.github.kevinsawicki.http.HttpRequest;
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException; import com.github.kevinsawicki.http.HttpRequest.HttpRequestException;
public class CordovaHttpGet extends CordovaHttp implements Runnable { class CordovaHttpGet extends CordovaHttp implements Runnable {
public CordovaHttpGet(String urlString, Map<?, ?> params, Map<String, String> headers, CallbackContext callbackContext) { public CordovaHttpGet(String urlString, JSONObject params, JSONObject headers, int timeout, CallbackContext callbackContext) {
super(urlString, params, headers, callbackContext); super(urlString, params, headers, timeout, callbackContext);
} }
@Override @Override
public void run() { public void run() {
try { try {
HttpRequest request = HttpRequest.get(this.getUrlString(), this.getParams(), true); HttpRequest request = HttpRequest.get(this.getUrlString(), this.getParamsMap(), false);
request.readTimeout(this.getRequestTimeout());
this.setupRedirect(request);
this.setupSecurity(request); this.setupSecurity(request);
request.acceptCharset(CHARSET); request.acceptCharset(CHARSET);
request.headers(this.getHeaders()); request.headers(this.getHeadersMap());
request.uncompress(true);
int code = request.code(); int code = request.code();
String body = request.body(CHARSET); String body = request.body(CHARSET);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
this.addResponseHeaders(request, response); this.addResponseHeaders(request, response);
response.put("status", code); response.put("status", code);
if (code >= 200 && code < 300) { if (code >= 200 && code < 300) {
response.put("data", body); response.put("data", body);
this.getCallbackContext().success(response); this.getCallbackContext().success(response);
@@ -54,6 +52,8 @@ public class CordovaHttpGet extends CordovaHttp implements Runnable {
} catch (HttpRequestException e) { } catch (HttpRequestException e) {
if (e.getCause() instanceof UnknownHostException) { if (e.getCause() instanceof UnknownHostException) {
this.respondWithError(0, "The host could not be resolved"); this.respondWithError(0, "The host could not be resolved");
} else if (e.getCause() instanceof SocketTimeoutException) {
this.respondWithError(1, "The request timed out");
} else if (e.getCause() instanceof SSLHandshakeException) { } else if (e.getCause() instanceof SSLHandshakeException) {
this.respondWithError("SSL handshake failed"); this.respondWithError("SSL handshake failed");
} else { } else {
@@ -61,4 +61,4 @@ public class CordovaHttpGet extends CordovaHttp implements Runnable {
} }
} }
} }
} }
@@ -1,18 +1,10 @@
/** /**
* A HTTP plugin for Cordova / Phonegap * A HTTP plugin for Cordova / Phonegap
*/ */
package com.synconset; package com.synconset.cordovahttp;
import java.io.IOException; import java.net.SocketTimeoutException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.util.Map;
import javax.net.ssl.HttpsURLConnection;
import javax.net.ssl.SSLContext;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
@@ -20,27 +12,32 @@ import org.apache.cordova.CallbackContext;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.util.Log;
import com.github.kevinsawicki.http.HttpRequest; import com.github.kevinsawicki.http.HttpRequest;
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException; import com.github.kevinsawicki.http.HttpRequest.HttpRequestException;
public class CordovaHttpHead extends CordovaHttp implements Runnable { class CordovaHttpHead extends CordovaHttp implements Runnable {
public CordovaHttpHead(String urlString, Map<?, ?> params, Map<String, String> headers, CallbackContext callbackContext) { public CordovaHttpHead(String urlString, JSONObject params, JSONObject headers, int timeout, CallbackContext callbackContext) {
super(urlString, params, headers, callbackContext); super(urlString, params, headers, timeout, callbackContext);
} }
@Override @Override
public void run() { public void run() {
try { try {
HttpRequest request = HttpRequest.head(this.getUrlString(), this.getParams(), true); HttpRequest request = HttpRequest.head(this.getUrlString(), this.getParamsMap(), true);
request.readTimeout(this.getRequestTimeout());
this.setupRedirect(request);
this.setupSecurity(request); this.setupSecurity(request);
request.acceptCharset(CHARSET); request.acceptCharset(CHARSET);
request.headers(this.getHeaders()); request.headers(this.getHeadersMap());
request.uncompress(true);
int code = request.code(); int code = request.code();
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
this.addResponseHeaders(request, response); this.addResponseHeaders(request, response);
response.put("status", code); response.put("status", code);
if (code >= 200 && code < 300) { if (code >= 200 && code < 300) {
// no 'body' to return for HEAD request // no 'body' to return for HEAD request
this.getCallbackContext().success(response); this.getCallbackContext().success(response);
@@ -54,6 +51,8 @@ public class CordovaHttpHead extends CordovaHttp implements Runnable {
} catch (HttpRequestException e) { } catch (HttpRequestException e) {
if (e.getCause() instanceof UnknownHostException) { if (e.getCause() instanceof UnknownHostException) {
this.respondWithError(0, "The host could not be resolved"); this.respondWithError(0, "The host could not be resolved");
} else if (e.getCause() instanceof SocketTimeoutException) {
this.respondWithError(1, "The request timed out");
} else if (e.getCause() instanceof SSLHandshakeException) { } else if (e.getCause() instanceof SSLHandshakeException) {
this.respondWithError("SSL handshake failed"); this.respondWithError("SSL handshake failed");
} else { } else {
@@ -61,4 +60,4 @@ public class CordovaHttpHead extends CordovaHttp implements Runnable {
} }
} }
} }
} }
@@ -0,0 +1,70 @@
/**
* A HTTP plugin for Cordova / Phonegap
*/
package com.synconset.cordovahttp;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import org.apache.cordova.CallbackContext;
import org.json.JSONException;
import org.json.JSONObject;
import javax.net.ssl.SSLHandshakeException;
import com.github.kevinsawicki.http.HttpRequest;
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException;
class CordovaHttpPatch extends CordovaHttp implements Runnable {
public CordovaHttpPatch(String urlString, JSONObject params, String serializerName, JSONObject headers, int timeout, CallbackContext callbackContext) {
super(urlString, params, serializerName, headers, timeout, callbackContext);
}
@Override
public void run() {
try {
HttpRequest request = HttpRequest.patch(this.getUrlString());
request.readTimeout(this.getRequestTimeout());
this.setupRedirect(request);
this.setupSecurity(request);
request.acceptCharset(CHARSET);
request.headers(this.getHeadersMap());
request.uncompress(true);
if (new String("json").equals(this.getSerializerName())) {
request.contentType(request.CONTENT_TYPE_JSON, request.CHARSET_UTF8);
request.send(this.getParamsObject().toString());
} else {
request.form(this.getParamsMap());
}
int code = request.code();
String body = request.body(CHARSET);
JSONObject response = new JSONObject();
this.addResponseHeaders(request, response);
response.put("status", code);
if (code >= 200 && code < 300) {
response.put("data", body);
this.getCallbackContext().success(response);
} else {
response.put("error", body);
this.getCallbackContext().error(response);
}
} catch (JSONException e) {
this.respondWithError("There was an error generating the response");
} catch (HttpRequestException e) {
if (e.getCause() instanceof UnknownHostException) {
this.respondWithError(0, "The host could not be resolved");
} else if (e.getCause() instanceof SocketTimeoutException) {
this.respondWithError(1, "The request timed out");
} else if (e.getCause() instanceof SSLHandshakeException) {
this.respondWithError("SSL handshake failed");
} else {
this.respondWithError("There was an error with the request");
}
}
}
}
@@ -1,39 +1,26 @@
/** /**
* A HTTP plugin for Cordova / Phonegap * A HTTP plugin for Cordova / Phonegap
*/ */
package com.synconset; package com.synconset.cordovahttp;
import java.io.BufferedInputStream; import java.io.BufferedInputStream;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
import java.net.HttpURLConnection;
import java.security.GeneralSecurityException;
import java.security.KeyStore;
import java.security.cert.Certificate;
import java.security.cert.CertificateException;
import java.security.cert.CertificateFactory;
import java.security.cert.X509Certificate;
import java.util.Iterator;
import java.util.ArrayList;
import java.util.HashMap;
import javax.net.ssl.HttpsURLConnection; import java.security.GeneralSecurityException;
import javax.net.ssl.SSLContext;
import javax.net.ssl.TrustManagerFactory; import java.util.ArrayList;
import javax.net.ssl.TrustManager;
import javax.net.ssl.HostnameVerifier;
import org.apache.cordova.CallbackContext; import org.apache.cordova.CallbackContext;
import org.apache.cordova.CordovaInterface; import org.apache.cordova.CordovaInterface;
import org.apache.cordova.CordovaPlugin; import org.apache.cordova.CordovaPlugin;
import org.apache.cordova.CordovaWebView; import org.apache.cordova.CordovaWebView;
import org.json.JSONArray; import org.json.JSONArray;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import android.content.res.AssetManager; import android.content.res.AssetManager;
import android.util.Base64;
import android.util.Log;
import com.github.kevinsawicki.http.HttpRequest; import com.github.kevinsawicki.http.HttpRequest;
@@ -47,30 +34,58 @@ public class CordovaHttpPlugin extends CordovaPlugin {
@Override @Override
public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException { public boolean execute(String action, final JSONArray args, final CallbackContext callbackContext) throws JSONException {
if (action.equals("get")) { if (action.equals("post")) {
String urlString = args.getString(0);
JSONObject params = args.getJSONObject(1);
String serializerName = args.getString(2);
JSONObject headers = args.getJSONObject(3);
int timeoutInMilliseconds = args.getInt(4) * 1000;
CordovaHttpPost post = new CordovaHttpPost(urlString, params, serializerName, headers, timeoutInMilliseconds, callbackContext);
cordova.getThreadPool().execute(post);
} else if (action.equals("get")) {
String urlString = args.getString(0); String urlString = args.getString(0);
JSONObject params = args.getJSONObject(1); JSONObject params = args.getJSONObject(1);
JSONObject headers = args.getJSONObject(2); JSONObject headers = args.getJSONObject(2);
HashMap<?, ?> paramsMap = this.getMapFromJSONObject(params); int timeoutInMilliseconds = args.getInt(3) * 1000;
HashMap<String, String> headersMap = this.getStringMapFromJSONObject(headers); CordovaHttpGet get = new CordovaHttpGet(urlString, params, headers, timeoutInMilliseconds, callbackContext);
CordovaHttpGet get = new CordovaHttpGet(urlString, paramsMap, headersMap, callbackContext);
cordova.getThreadPool().execute(get); cordova.getThreadPool().execute(get);
} else if (action.equals("put")) {
String urlString = args.getString(0);
JSONObject params = args.getJSONObject(1);
String serializerName = args.getString(2);
JSONObject headers = args.getJSONObject(3);
int timeoutInMilliseconds = args.getInt(4) * 1000;
CordovaHttpPut put = new CordovaHttpPut(urlString, params, serializerName, headers, timeoutInMilliseconds, callbackContext);
cordova.getThreadPool().execute(put);
} else if (action.equals("patch")) {
String urlString = args.getString(0);
JSONObject params = args.getJSONObject(1);
String serializerName = args.getString(2);
JSONObject headers = args.getJSONObject(3);
int timeoutInMilliseconds = args.getInt(4) * 1000;
CordovaHttpPatch patch = new CordovaHttpPatch(urlString, params, serializerName, headers, timeoutInMilliseconds, callbackContext);
cordova.getThreadPool().execute(patch);
}
else if (action.equals("delete")) {
String urlString = args.getString(0);
JSONObject params = args.getJSONObject(1);
JSONObject headers = args.getJSONObject(2);
int timeoutInMilliseconds = args.getInt(3) * 1000;
CordovaHttpDelete delete = new CordovaHttpDelete(urlString, params, headers, timeoutInMilliseconds, callbackContext);
cordova.getThreadPool().execute(delete);
} else if (action.equals("head")) { } else if (action.equals("head")) {
String urlString = args.getString(0); String urlString = args.getString(0);
JSONObject params = args.getJSONObject(1); JSONObject params = args.getJSONObject(1);
JSONObject headers = args.getJSONObject(2); JSONObject headers = args.getJSONObject(2);
HashMap<?, ?> paramsMap = this.getMapFromJSONObject(params); int timeoutInMilliseconds = args.getInt(3) * 1000;
HashMap<String, String> headersMap = this.getStringMapFromJSONObject(headers); CordovaHttpHead head = new CordovaHttpHead(urlString, params, headers, timeoutInMilliseconds, callbackContext);
CordovaHttpHead head = new CordovaHttpHead(urlString, paramsMap, headersMap, callbackContext);
cordova.getThreadPool().execute(head); cordova.getThreadPool().execute(head);
} else if (action.equals("post")) {
String urlString = args.getString(0);
JSONObject params = args.getJSONObject(1);
JSONObject headers = args.getJSONObject(2);
HashMap<?, ?> paramsMap = this.getMapFromJSONObject(params);
HashMap<String, String> headersMap = this.getStringMapFromJSONObject(headers);
CordovaHttpPost post = new CordovaHttpPost(urlString, paramsMap, headersMap, callbackContext);
cordova.getThreadPool().execute(post);
} else if (action.equals("enableSSLPinning")) { } else if (action.equals("enableSSLPinning")) {
try { try {
boolean enable = args.getBoolean(0); boolean enable = args.getBoolean(0);
@@ -82,31 +97,33 @@ public class CordovaHttpPlugin extends CordovaPlugin {
} }
} else if (action.equals("acceptAllCerts")) { } else if (action.equals("acceptAllCerts")) {
boolean accept = args.getBoolean(0); boolean accept = args.getBoolean(0);
CordovaHttp.acceptAllCerts(accept); CordovaHttp.acceptAllCerts(accept);
callbackContext.success(); CordovaHttp.validateDomainName(!accept);
} else if (action.equals("validateDomainName")) {
boolean accept = args.getBoolean(0);
CordovaHttp.validateDomainName(accept);
callbackContext.success(); callbackContext.success();
} else if (action.equals("uploadFile")) { } else if (action.equals("uploadFile")) {
String urlString = args.getString(0); String urlString = args.getString(0);
JSONObject params = args.getJSONObject(1); JSONObject params = args.getJSONObject(1);
JSONObject headers = args.getJSONObject(2); JSONObject headers = args.getJSONObject(2);
HashMap<?, ?> paramsMap = this.getMapFromJSONObject(params);
HashMap<String, String> headersMap = this.getStringMapFromJSONObject(headers);
String filePath = args.getString(3); String filePath = args.getString(3);
String name = args.getString(4); String name = args.getString(4);
CordovaHttpUpload upload = new CordovaHttpUpload(urlString, paramsMap, headersMap, callbackContext, filePath, name); int timeoutInMilliseconds = args.getInt(5) * 1000;
CordovaHttpUpload upload = new CordovaHttpUpload(urlString, params, headers, filePath, name, timeoutInMilliseconds, callbackContext);
cordova.getThreadPool().execute(upload); cordova.getThreadPool().execute(upload);
} else if (action.equals("downloadFile")) { } else if (action.equals("downloadFile")) {
String urlString = args.getString(0); String urlString = args.getString(0);
JSONObject params = args.getJSONObject(1); JSONObject params = args.getJSONObject(1);
JSONObject headers = args.getJSONObject(2); JSONObject headers = args.getJSONObject(2);
HashMap<?, ?> paramsMap = this.getMapFromJSONObject(params);
HashMap<String, String> headersMap = this.getStringMapFromJSONObject(headers);
String filePath = args.getString(3); String filePath = args.getString(3);
CordovaHttpDownload download = new CordovaHttpDownload(urlString, paramsMap, headersMap, callbackContext, filePath); int timeoutInMilliseconds = args.getInt(4) * 1000;
CordovaHttpDownload download = new CordovaHttpDownload(urlString, params, headers, filePath, timeoutInMilliseconds, callbackContext);
cordova.getThreadPool().execute(download); cordova.getThreadPool().execute(download);
} else if (action.equals("disableRedirect")) {
boolean disable = args.getBoolean(0);
CordovaHttp.disableRedirect(disable);
callbackContext.success();
} else { } else {
return false; return false;
} }
@@ -149,26 +166,4 @@ public class CordovaHttpPlugin extends CordovaPlugin {
CordovaHttp.enableSSLPinning(false); CordovaHttp.enableSSLPinning(false);
} }
} }
private HashMap<String, String> getStringMapFromJSONObject(JSONObject object) throws JSONException {
HashMap<String, String> map = new HashMap<String, String>();
Iterator<?> i = object.keys();
while (i.hasNext()) {
String key = (String)i.next();
map.put(key, object.getString(key));
}
return map;
}
private HashMap<String, Object> getMapFromJSONObject(JSONObject object) throws JSONException {
HashMap<String, Object> map = new HashMap<String, Object>();
Iterator<?> i = object.keys();
while(i.hasNext()) {
String key = (String)i.next();
map.put(key, object.get(key));
}
return map;
}
} }
@@ -0,0 +1,70 @@
/**
* A HTTP plugin for Cordova / Phonegap
*/
package com.synconset.cordovahttp;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import org.apache.cordova.CallbackContext;
import org.json.JSONException;
import org.json.JSONObject;
import javax.net.ssl.SSLHandshakeException;
import com.github.kevinsawicki.http.HttpRequest;
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException;
class CordovaHttpPost extends CordovaHttp implements Runnable {
public CordovaHttpPost(String urlString, JSONObject params, String serializerName, JSONObject headers, int timeout, CallbackContext callbackContext) {
super(urlString, params, serializerName, headers, timeout, callbackContext);
}
@Override
public void run() {
try {
HttpRequest request = HttpRequest.post(this.getUrlString());
request.readTimeout(this.getRequestTimeout());
this.setupRedirect(request);
this.setupSecurity(request);
request.acceptCharset(CHARSET);
request.headers(this.getHeadersMap());
request.uncompress(true);
if (new String("json").equals(this.getSerializerName())) {
request.contentType(request.CONTENT_TYPE_JSON, request.CHARSET_UTF8);
request.send(this.getParamsObject().toString());
} else {
request.form(this.getParamsMap());
}
int code = request.code();
String body = request.body(CHARSET);
JSONObject response = new JSONObject();
this.addResponseHeaders(request, response);
response.put("status", code);
if (code >= 200 && code < 300) {
response.put("data", body);
this.getCallbackContext().success(response);
} else {
response.put("error", body);
this.getCallbackContext().error(response);
}
} catch (JSONException e) {
this.respondWithError("There was an error generating the response");
} catch (HttpRequestException e) {
if (e.getCause() instanceof UnknownHostException) {
this.respondWithError(0, "The host could not be resolved");
} else if (e.getCause() instanceof SocketTimeoutException) {
this.respondWithError(1, "The request timed out");
} else if (e.getCause() instanceof SSLHandshakeException) {
this.respondWithError("SSL handshake failed");
} else {
this.respondWithError("There was an error with the request");
}
}
}
}
@@ -0,0 +1,70 @@
/**
* A HTTP plugin for Cordova / Phonegap
*/
package com.synconset.cordovahttp;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;
import org.apache.cordova.CallbackContext;
import org.json.JSONException;
import org.json.JSONObject;
import javax.net.ssl.SSLHandshakeException;
import com.github.kevinsawicki.http.HttpRequest;
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException;
class CordovaHttpPut extends CordovaHttp implements Runnable {
public CordovaHttpPut(String urlString, JSONObject data, String serializerName, JSONObject headers, int timeout, CallbackContext callbackContext) {
super(urlString, data, serializerName, headers, timeout, callbackContext);
}
@Override
public void run() {
try {
HttpRequest request = HttpRequest.put(this.getUrlString());
request.readTimeout(this.getRequestTimeout());
this.setupRedirect(request);
this.setupSecurity(request);
request.acceptCharset(CHARSET);
request.headers(this.getHeadersMap());
request.uncompress(true);
if (new String("json").equals(this.getSerializerName())) {
request.contentType(request.CONTENT_TYPE_JSON, request.CHARSET_UTF8);
request.send(this.getParamsObject().toString());
} else {
request.form(this.getParamsMap());
}
int code = request.code();
String body = request.body(CHARSET);
JSONObject response = new JSONObject();
this.addResponseHeaders(request, response);
response.put("status", code);
if (code >= 200 && code < 300) {
response.put("data", body);
this.getCallbackContext().success(response);
} else {
response.put("error", body);
this.getCallbackContext().error(response);
}
} catch (JSONException e) {
this.respondWithError("There was an error generating the response");
} catch (HttpRequestException e) {
if (e.getCause() instanceof UnknownHostException) {
this.respondWithError(0, "The host could not be resolved");
} else if (e.getCause() instanceof SocketTimeoutException) {
this.respondWithError(1, "The request timed out");
} else if (e.getCause() instanceof SSLHandshakeException) {
this.respondWithError("SSL handshake failed");
} else {
this.respondWithError("There was an error with the request");
}
}
}
}
@@ -1,57 +1,69 @@
/** /**
* A HTTP plugin for Cordova / Phonegap * A HTTP plugin for Cordova / Phonegap
*/ */
package com.synconset; package com.synconset.cordovahttp;
import java.io.File; import java.io.File;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException; import java.net.UnknownHostException;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.Iterator; import java.util.Iterator;
import java.util.Map;
import java.util.Map.Entry; import java.util.Map.Entry;
import java.util.Set; import java.util.Set;
import org.apache.cordova.CallbackContext; import org.apache.cordova.CallbackContext;
import org.json.JSONException; import org.json.JSONException;
import org.json.JSONObject; import org.json.JSONObject;
import javax.net.ssl.SSLHandshakeException; import javax.net.ssl.SSLHandshakeException;
import android.util.Log;
import android.webkit.MimeTypeMap; import android.webkit.MimeTypeMap;
import com.github.kevinsawicki.http.HttpRequest; import com.github.kevinsawicki.http.HttpRequest;
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException; import com.github.kevinsawicki.http.HttpRequest.HttpRequestException;
public class CordovaHttpUpload extends CordovaHttp implements Runnable { class CordovaHttpUpload extends CordovaHttp implements Runnable {
private String filePath; private String filePath;
private String name; private String name;
public CordovaHttpUpload(String urlString, Map<?, ?> params, Map<String, String> headers, CallbackContext callbackContext, String filePath, String name) { public CordovaHttpUpload(String urlString, JSONObject params, JSONObject headers, String filePath, String name, int timeout, CallbackContext callbackContext) {
super(urlString, params, headers, callbackContext); super(urlString, params, headers, timeout, callbackContext);
this.filePath = filePath; this.filePath = filePath;
this.name = name; this.name = name;
} }
@Override @Override
public void run() { public void run() {
try { try {
HttpRequest request = HttpRequest.post(this.getUrlString()); HttpRequest request = HttpRequest.post(this.getUrlString());
request.readTimeout(this.getRequestTimeout());
this.setupRedirect(request);
this.setupSecurity(request); this.setupSecurity(request);
request.acceptCharset(CHARSET); request.acceptCharset(CHARSET);
request.headers(this.getHeaders()); request.headers(this.getHeadersMap());
request.uncompress(true);
URI uri = new URI(filePath); URI uri = new URI(filePath);
int index = filePath.lastIndexOf('/');
String filename = filePath.substring(index + 1); int filenameIndex = filePath.lastIndexOf('/');
index = filePath.lastIndexOf('.'); String filename = filePath.substring(filenameIndex + 1);
String ext = filePath.substring(index + 1);
int extIndex = filePath.lastIndexOf('.');
String ext = filePath.substring(extIndex + 1);
MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton(); MimeTypeMap mimeTypeMap = MimeTypeMap.getSingleton();
String mimeType = mimeTypeMap.getMimeTypeFromExtension(ext); String mimeType = mimeTypeMap.getMimeTypeFromExtension(ext);
request.part(this.name, filename, mimeType, new File(uri)); request.part(this.name, filename, mimeType, new File(uri));
Set<?> set = (Set<?>)this.getParams().entrySet(); Set<?> set = (Set<?>)this.getParamsMap().entrySet();
Iterator<?> i = set.iterator(); Iterator<?> i = set.iterator();
while (i.hasNext()) { while (i.hasNext()) {
Entry<?, ?> e = (Entry<?, ?>)i.next(); Entry<?, ?> e = (Entry<?, ?>)i.next();
String key = (String)e.getKey(); String key = (String)e.getKey();
@@ -65,13 +77,15 @@ public class CordovaHttpUpload extends CordovaHttp implements Runnable {
return; return;
} }
} }
int code = request.code(); int code = request.code();
String body = request.body(CHARSET); String body = request.body(CHARSET);
JSONObject response = new JSONObject(); JSONObject response = new JSONObject();
this.addResponseHeaders(request, response); this.addResponseHeaders(request, response);
response.put("status", code); response.put("status", code);
if (code >= 200 && code < 300) { if (code >= 200 && code < 300) {
response.put("data", body); response.put("data", body);
this.getCallbackContext().success(response); this.getCallbackContext().success(response);
@@ -86,6 +100,8 @@ public class CordovaHttpUpload extends CordovaHttp implements Runnable {
} catch (HttpRequestException e) { } catch (HttpRequestException e) {
if (e.getCause() instanceof UnknownHostException) { if (e.getCause() instanceof UnknownHostException) {
this.respondWithError(0, "The host could not be resolved"); this.respondWithError(0, "The host could not be resolved");
} else if (e.getCause() instanceof SocketTimeoutException) {
this.respondWithError(1, "The request timed out");
} else if (e.getCause() instanceof SSLHandshakeException) { } else if (e.getCause() instanceof SSLHandshakeException) {
this.respondWithError("SSL handshake failed"); this.respondWithError("SSL handshake failed");
} else { } else {
+7 -7
View File
@@ -1,5 +1,5 @@
// AFHTTPSessionManager.h // AFHTTPSessionManager.h
// Copyright (c) 20112016 Alamofire Software Foundation (http://alamofire.org/) // Copyright (c) 20112016 Alamofire Software Foundation ( http://alamofire.org/ )
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -150,7 +150,7 @@ NS_ASSUME_NONNULL_BEGIN
@param URLString The URL string used to create the request URL. @param URLString The URL string used to create the request URL.
@param parameters The parameters to be encoded according to the client request serializer. @param parameters The parameters to be encoded according to the client request serializer.
@param progress A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue. @param downloadProgress A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.
@param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer. @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
@param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred. @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
@@ -158,7 +158,7 @@ NS_ASSUME_NONNULL_BEGIN
*/ */
- (nullable NSURLSessionDataTask *)GET:(NSString *)URLString - (nullable NSURLSessionDataTask *)GET:(NSString *)URLString
parameters:(nullable id)parameters parameters:(nullable id)parameters
progress:(nullable void (^)(NSProgress *downloadProgress)) downloadProgress progress:(nullable void (^)(NSProgress *downloadProgress))downloadProgress
success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure; failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
@@ -197,7 +197,7 @@ NS_ASSUME_NONNULL_BEGIN
@param URLString The URL string used to create the request URL. @param URLString The URL string used to create the request URL.
@param parameters The parameters to be encoded according to the client request serializer. @param parameters The parameters to be encoded according to the client request serializer.
@param progress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. @param uploadProgress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
@param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer. @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
@param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred. @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
@@ -205,7 +205,7 @@ NS_ASSUME_NONNULL_BEGIN
*/ */
- (nullable NSURLSessionDataTask *)POST:(NSString *)URLString - (nullable NSURLSessionDataTask *)POST:(NSString *)URLString
parameters:(nullable id)parameters parameters:(nullable id)parameters
progress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgress progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgress
success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure; failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
@@ -232,7 +232,7 @@ NS_ASSUME_NONNULL_BEGIN
@param URLString The URL string used to create the request URL. @param URLString The URL string used to create the request URL.
@param parameters The parameters to be encoded according to the client request serializer. @param parameters The parameters to be encoded according to the client request serializer.
@param block A block that takes a single argument and appends data to the HTTP body. The block argument is an object adopting the `AFMultipartFormData` protocol. @param block A block that takes a single argument and appends data to the HTTP body. The block argument is an object adopting the `AFMultipartFormData` protocol.
@param progress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. @param uploadProgress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
@param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer. @param success A block object to be executed when the task finishes successfully. This block has no return value and takes two arguments: the data task, and the response object created by the client response serializer.
@param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred. @param failure A block object to be executed when the task finishes unsuccessfully, or that finishes successfully, but encountered an error while parsing the response data. This block has no return value and takes a two arguments: the data task and the error describing the network or parsing error that occurred.
@@ -241,7 +241,7 @@ NS_ASSUME_NONNULL_BEGIN
- (nullable NSURLSessionDataTask *)POST:(NSString *)URLString - (nullable NSURLSessionDataTask *)POST:(NSString *)URLString
parameters:(nullable id)parameters parameters:(nullable id)parameters
constructingBodyWithBlock:(nullable void (^)(id <AFMultipartFormData> formData))block constructingBodyWithBlock:(nullable void (^)(id <AFMultipartFormData> formData))block
progress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgress progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgress
success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success success:(nullable void (^)(NSURLSessionDataTask *task, id _Nullable responseObject))success
failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure; failure:(nullable void (^)(NSURLSessionDataTask * _Nullable task, NSError *error))failure;
+1 -7
View File
@@ -1,5 +1,5 @@
// AFHTTPSessionManager.m // AFHTTPSessionManager.m
// Copyright (c) 20112016 Alamofire Software Foundation (http://alamofire.org/) // Copyright (c) 20112016 Alamofire Software Foundation ( http://alamofire.org/ )
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -186,12 +186,9 @@
NSMutableURLRequest *request = [self.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters constructingBodyWithBlock:block error:&serializationError]; NSMutableURLRequest *request = [self.requestSerializer multipartFormRequestWithMethod:@"POST" URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters constructingBodyWithBlock:block error:&serializationError];
if (serializationError) { if (serializationError) {
if (failure) { if (failure) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu"
dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{ dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{
failure(nil, serializationError); failure(nil, serializationError);
}); });
#pragma clang diagnostic pop
} }
return nil; return nil;
@@ -262,12 +259,9 @@
NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:method URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&serializationError]; NSMutableURLRequest *request = [self.requestSerializer requestWithMethod:method URLString:[[NSURL URLWithString:URLString relativeToURL:self.baseURL] absoluteString] parameters:parameters error:&serializationError];
if (serializationError) { if (serializationError) {
if (failure) { if (failure) {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu"
dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{ dispatch_async(self.completionQueue ?: dispatch_get_main_queue(), ^{
failure(nil, serializationError); failure(nil, serializationError);
}); });
#pragma clang diagnostic pop
} }
return nil; return nil;
@@ -1,5 +1,5 @@
// AFNetworkReachabilityManager.h // AFNetworkReachabilityManager.h
// Copyright (c) 20112016 Alamofire Software Foundation (http://alamofire.org/) // Copyright (c) 20112016 Alamofire Software Foundation ( http://alamofire.org/ )
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -38,7 +38,7 @@ NS_ASSUME_NONNULL_BEGIN
Reachability can be used to determine background information about why a network operation failed, or to trigger a network operation retrying when a connection is established. It should not be used to prevent a user from initiating a network request, as it's possible that an initial request may be required to establish reachability. Reachability can be used to determine background information about why a network operation failed, or to trigger a network operation retrying when a connection is established. It should not be used to prevent a user from initiating a network request, as it's possible that an initial request may be required to establish reachability.
See Apple's Reachability Sample Code (https://developer.apple.com/library/ios/samplecode/reachability/) See Apple's Reachability Sample Code ( https://developer.apple.com/library/ios/samplecode/reachability/ )
@warning Instances of `AFNetworkReachabilityManager` must be started with `-startMonitoring` before reachability status can be determined. @warning Instances of `AFNetworkReachabilityManager` must be started with `-startMonitoring` before reachability status can be determined.
*/ */
@@ -1,5 +1,5 @@
// AFNetworkReachabilityManager.m // AFNetworkReachabilityManager.m
// Copyright (c) 20112016 Alamofire Software Foundation (http://alamofire.org/) // Copyright (c) 20112016 Alamofire Software Foundation ( http://alamofire.org/ )
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,5 +1,5 @@
// AFSecurityPolicy.h // AFSecurityPolicy.h
// Copyright (c) 20112016 Alamofire Software Foundation (http://alamofire.org/) // Copyright (c) 20112016 Alamofire Software Foundation ( http://alamofire.org/ )
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
+1 -1
View File
@@ -1,5 +1,5 @@
// AFSecurityPolicy.m // AFSecurityPolicy.m
// Copyright (c) 20112016 Alamofire Software Foundation (http://alamofire.org/) // Copyright (c) 20112016 Alamofire Software Foundation ( http://alamofire.org/ )
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
// AFURLRequestSerialization.h // AFURLRequestSerialization.h
// Copyright (c) 20112016 Alamofire Software Foundation (http://alamofire.org/) // Copyright (c) 20112016 Alamofire Software Foundation ( http://alamofire.org/ )
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
// AFURLRequestSerialization.m // AFURLRequestSerialization.m
// Copyright (c) 20112016 Alamofire Software Foundation (http://alamofire.org/) // Copyright (c) 20112016 Alamofire Software Foundation ( http://alamofire.org/ )
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -60,10 +60,7 @@ NSString * AFPercentEscapedStringFromString(NSString *string) {
NSMutableString *escaped = @"".mutableCopy; NSMutableString *escaped = @"".mutableCopy;
while (index < string.length) { while (index < string.length) {
#pragma GCC diagnostic push
#pragma GCC diagnostic ignored "-Wgnu"
NSUInteger length = MIN(string.length - index, batchSize); NSUInteger length = MIN(string.length - index, batchSize);
#pragma GCC diagnostic pop
NSRange range = NSMakeRange(index, length); NSRange range = NSMakeRange(index, length);
// To avoid breaking up character sequences such as 👴🏻👮🏽 // To avoid breaking up character sequences such as 👴🏻👮🏽
@@ -219,8 +216,6 @@ static void *AFHTTPRequestSerializerObserverContext = &AFHTTPRequestSerializerOb
[self setValue:[acceptLanguagesComponents componentsJoinedByString:@", "] forHTTPHeaderField:@"Accept-Language"]; [self setValue:[acceptLanguagesComponents componentsJoinedByString:@", "] forHTTPHeaderField:@"Accept-Language"];
NSString *userAgent = nil; NSString *userAgent = nil;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu"
#if TARGET_OS_IOS #if TARGET_OS_IOS
// User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43 // User-Agent Header; see http://www.w3.org/Protocols/rfc2616/rfc2616-sec14.html#sec14.43
userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]]; userAgent = [NSString stringWithFormat:@"%@/%@ (%@; iOS %@; Scale/%0.2f)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[UIDevice currentDevice] model], [[UIDevice currentDevice] systemVersion], [[UIScreen mainScreen] scale]];
@@ -230,7 +225,6 @@ static void *AFHTTPRequestSerializerObserverContext = &AFHTTPRequestSerializerOb
#elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED) #elif defined(__MAC_OS_X_VERSION_MIN_REQUIRED)
userAgent = [NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]]; userAgent = [NSString stringWithFormat:@"%@/%@ (Mac OS X %@)", [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleExecutableKey] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleIdentifierKey], [[NSBundle mainBundle] infoDictionary][@"CFBundleShortVersionString"] ?: [[NSBundle mainBundle] infoDictionary][(__bridge NSString *)kCFBundleVersionKey], [[NSProcessInfo processInfo] operatingSystemVersionString]];
#endif #endif
#pragma clang diagnostic pop
if (userAgent) { if (userAgent) {
if (![userAgent canBeConvertedToEncoding:NSASCIIStringEncoding]) { if (![userAgent canBeConvertedToEncoding:NSASCIIStringEncoding]) {
NSMutableString *mutableUserAgent = [userAgent mutableCopy]; NSMutableString *mutableUserAgent = [userAgent mutableCopy];
@@ -500,7 +494,7 @@ forHTTPHeaderField:(NSString *)field
} }
if ([self.HTTPMethodsEncodingParametersInURI containsObject:[[request HTTPMethod] uppercaseString]]) { if ([self.HTTPMethodsEncodingParametersInURI containsObject:[[request HTTPMethod] uppercaseString]]) {
if (query) { if (query && query.length > 0) {
mutableRequest.URL = [NSURL URLWithString:[[mutableRequest.URL absoluteString] stringByAppendingFormat:mutableRequest.URL.query ? @"&%@" : @"?%@", query]]; mutableRequest.URL = [NSURL URLWithString:[[mutableRequest.URL absoluteString] stringByAppendingFormat:mutableRequest.URL.query ? @"&%@" : @"?%@", query]];
} }
} else { } else {
@@ -835,14 +829,11 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
@end @end
@implementation AFMultipartBodyStream @implementation AFMultipartBodyStream
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wimplicit-atomic-properties"
#if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1100) #if (defined(__IPHONE_OS_VERSION_MAX_ALLOWED) && __IPHONE_OS_VERSION_MAX_ALLOWED >= 80000) || (defined(__MAC_OS_X_VERSION_MAX_ALLOWED) && __MAC_OS_X_VERSION_MAX_ALLOWED >= 1100)
@synthesize delegate; @synthesize delegate;
#endif #endif
@synthesize streamStatus; @synthesize streamStatus;
@synthesize streamError; @synthesize streamError;
#pragma clang diagnostic pop
- (instancetype)initWithStringEncoding:(NSStringEncoding)encoding { - (instancetype)initWithStringEncoding:(NSStringEncoding)encoding {
self = [super init]; self = [super init];
@@ -888,8 +879,6 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
NSInteger totalNumberOfBytesRead = 0; NSInteger totalNumberOfBytesRead = 0;
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu"
while ((NSUInteger)totalNumberOfBytesRead < MIN(length, self.numberOfBytesInPacket)) { while ((NSUInteger)totalNumberOfBytesRead < MIN(length, self.numberOfBytesInPacket)) {
if (!self.currentHTTPBodyPart || ![self.currentHTTPBodyPart hasBytesAvailable]) { if (!self.currentHTTPBodyPart || ![self.currentHTTPBodyPart hasBytesAvailable]) {
if (!(self.currentHTTPBodyPart = [self.HTTPBodyPartEnumerator nextObject])) { if (!(self.currentHTTPBodyPart = [self.HTTPBodyPartEnumerator nextObject])) {
@@ -910,7 +899,6 @@ NSTimeInterval const kAFUploadStream3GSuggestedDelay = 0.2;
} }
} }
} }
#pragma clang diagnostic pop
return totalNumberOfBytesRead; return totalNumberOfBytesRead;
} }
@@ -1091,8 +1079,6 @@ typedef enum {
return YES; return YES;
} }
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcovered-switch-default"
switch (self.inputStream.streamStatus) { switch (self.inputStream.streamStatus) {
case NSStreamStatusNotOpen: case NSStreamStatusNotOpen:
case NSStreamStatusOpening: case NSStreamStatusOpening:
@@ -1106,7 +1092,6 @@ typedef enum {
default: default:
return NO; return NO;
} }
#pragma clang diagnostic pop
} }
- (NSInteger)read:(uint8_t *)buffer - (NSInteger)read:(uint8_t *)buffer
@@ -1151,11 +1136,8 @@ typedef enum {
intoBuffer:(uint8_t *)buffer intoBuffer:(uint8_t *)buffer
maxLength:(NSUInteger)length maxLength:(NSUInteger)length
{ {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu"
NSRange range = NSMakeRange((NSUInteger)_phaseReadOffset, MIN([data length] - ((NSUInteger)_phaseReadOffset), length)); NSRange range = NSMakeRange((NSUInteger)_phaseReadOffset, MIN([data length] - ((NSUInteger)_phaseReadOffset), length));
[data getBytes:buffer range:range]; [data getBytes:buffer range:range];
#pragma clang diagnostic pop
_phaseReadOffset += range.length; _phaseReadOffset += range.length;
@@ -1174,8 +1156,6 @@ typedef enum {
return YES; return YES;
} }
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wcovered-switch-default"
switch (_phase) { switch (_phase) {
case AFEncapsulationBoundaryPhase: case AFEncapsulationBoundaryPhase:
_phase = AFHeaderPhase; _phase = AFHeaderPhase;
@@ -1195,7 +1175,6 @@ typedef enum {
break; break;
} }
_phaseReadOffset = 0; _phaseReadOffset = 0;
#pragma clang diagnostic pop
return YES; return YES;
} }
@@ -1,5 +1,5 @@
// AFURLResponseSerialization.h // AFURLResponseSerialization.h
// Copyright (c) 20112016 Alamofire Software Foundation (http://alamofire.org/) // Copyright (c) 20112016 Alamofire Software Foundation ( http://alamofire.org/ )
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -1,5 +1,5 @@
// AFURLResponseSerialization.m // AFURLResponseSerialization.m
// Copyright (c) 20112016 Alamofire Software Foundation (http://alamofire.org/) // Copyright (c) 20112016 Alamofire Software Foundation ( http://alamofire.org/ )
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -115,7 +115,9 @@ static id AFJSONObjectByRemovingKeysWithNullValues(id JSONObject, NSJSONReadingO
NSError *validationError = nil; NSError *validationError = nil;
if (response && [response isKindOfClass:[NSHTTPURLResponse class]]) { if (response && [response isKindOfClass:[NSHTTPURLResponse class]]) {
if (self.acceptableContentTypes && ![self.acceptableContentTypes containsObject:[response MIMEType]]) { if (self.acceptableContentTypes && ![self.acceptableContentTypes containsObject:[response MIMEType]] &&
!([response MIMEType] == nil && [data length] == 0)) {
if ([data length] > 0 && [response URL]) { if ([data length] > 0 && [response URL]) {
NSMutableDictionary *mutableUserInfo = [@{ NSMutableDictionary *mutableUserInfo = [@{
NSLocalizedDescriptionKey: [NSString stringWithFormat:NSLocalizedStringFromTable(@"Request failed: unacceptable content-type: %@", @"AFNetworking", nil), [response MIMEType]], NSLocalizedDescriptionKey: [NSString stringWithFormat:NSLocalizedStringFromTable(@"Request failed: unacceptable content-type: %@", @"AFNetworking", nil), [response MIMEType]],
+16 -15
View File
@@ -1,5 +1,5 @@
// AFURLSessionManager.h // AFURLSessionManager.h
// Copyright (c) 20112016 Alamofire Software Foundation (http://alamofire.org/) // Copyright (c) 20112016 Alamofire Software Foundation ( http://alamofire.org/ )
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -51,6 +51,7 @@
- `URLSession:willPerformHTTPRedirection:newRequest:completionHandler:` - `URLSession:willPerformHTTPRedirection:newRequest:completionHandler:`
- `URLSession:task:didReceiveChallenge:completionHandler:` - `URLSession:task:didReceiveChallenge:completionHandler:`
- `URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:` - `URLSession:task:didSendBodyData:totalBytesSent:totalBytesExpectedToSend:`
- `URLSession:task:needNewBodyStream:`
- `URLSession:task:didCompleteWithError:` - `URLSession:task:didCompleteWithError:`
### `NSURLSessionDataDelegate` ### `NSURLSessionDataDelegate`
@@ -213,13 +214,13 @@ NS_ASSUME_NONNULL_BEGIN
Creates an `NSURLSessionDataTask` with the specified request. Creates an `NSURLSessionDataTask` with the specified request.
@param request The HTTP request for the request. @param request The HTTP request for the request.
@param uploadProgress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. @param uploadProgressBlock A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
@param downloadProgress A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue. @param downloadProgressBlock A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.
@param completionHandler A block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any. @param completionHandler A block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any.
*/ */
- (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request - (NSURLSessionDataTask *)dataTaskWithRequest:(NSURLRequest *)request
uploadProgress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgressBlock uploadProgress:(nullable void (^)(NSProgress *uploadProgress))uploadProgressBlock
downloadProgress:(nullable void (^)(NSProgress *downloadProgress)) downloadProgressBlock downloadProgress:(nullable void (^)(NSProgress *downloadProgress))downloadProgressBlock
completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler; completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler;
///--------------------------- ///---------------------------
@@ -231,14 +232,14 @@ NS_ASSUME_NONNULL_BEGIN
@param request The HTTP request for the request. @param request The HTTP request for the request.
@param fileURL A URL to the local file to be uploaded. @param fileURL A URL to the local file to be uploaded.
@param progress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. @param uploadProgressBlock A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
@param completionHandler A block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any. @param completionHandler A block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any.
@see `attemptsToRecreateUploadTasksForBackgroundSessions` @see `attemptsToRecreateUploadTasksForBackgroundSessions`
*/ */
- (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request
fromFile:(NSURL *)fileURL fromFile:(NSURL *)fileURL
progress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgressBlock progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgressBlock
completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler; completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler;
/** /**
@@ -246,23 +247,23 @@ NS_ASSUME_NONNULL_BEGIN
@param request The HTTP request for the request. @param request The HTTP request for the request.
@param bodyData A data object containing the HTTP body to be uploaded. @param bodyData A data object containing the HTTP body to be uploaded.
@param progress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. @param uploadProgressBlock A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
@param completionHandler A block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any. @param completionHandler A block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any.
*/ */
- (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request - (NSURLSessionUploadTask *)uploadTaskWithRequest:(NSURLRequest *)request
fromData:(nullable NSData *)bodyData fromData:(nullable NSData *)bodyData
progress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgressBlock progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgressBlock
completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler; completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler;
/** /**
Creates an `NSURLSessionUploadTask` with the specified streaming request. Creates an `NSURLSessionUploadTask` with the specified streaming request.
@param request The HTTP request for the request. @param request The HTTP request for the request.
@param progress A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue. @param uploadProgressBlock A block object to be executed when the upload progress is updated. Note this block is called on the session queue, not the main queue.
@param completionHandler A block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any. @param completionHandler A block object to be executed when the task finishes. This block has no return value and takes three arguments: the server response, the response object created by that serializer, and the error that occurred, if any.
*/ */
- (NSURLSessionUploadTask *)uploadTaskWithStreamedRequest:(NSURLRequest *)request - (NSURLSessionUploadTask *)uploadTaskWithStreamedRequest:(NSURLRequest *)request
progress:(nullable void (^)(NSProgress *uploadProgress)) uploadProgressBlock progress:(nullable void (^)(NSProgress *uploadProgress))uploadProgressBlock
completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler; completionHandler:(nullable void (^)(NSURLResponse *response, id _Nullable responseObject, NSError * _Nullable error))completionHandler;
///----------------------------- ///-----------------------------
@@ -273,14 +274,14 @@ NS_ASSUME_NONNULL_BEGIN
Creates an `NSURLSessionDownloadTask` with the specified request. Creates an `NSURLSessionDownloadTask` with the specified request.
@param request The HTTP request for the request. @param request The HTTP request for the request.
@param progress A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue. @param downloadProgressBlock A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.
@param destination A block object to be executed in order to determine the destination of the downloaded file. This block takes two arguments, the target path & the server response, and returns the desired file URL of the resulting download. The temporary file used during the download will be automatically deleted after being moved to the returned URL. @param destination A block object to be executed in order to determine the destination of the downloaded file. This block takes two arguments, the target path & the server response, and returns the desired file URL of the resulting download. The temporary file used during the download will be automatically deleted after being moved to the returned URL.
@param completionHandler A block to be executed when a task finishes. This block has no return value and takes three arguments: the server response, the path of the downloaded file, and the error describing the network or parsing error that occurred, if any. @param completionHandler A block to be executed when a task finishes. This block has no return value and takes three arguments: the server response, the path of the downloaded file, and the error describing the network or parsing error that occurred, if any.
@warning If using a background `NSURLSessionConfiguration` on iOS, these blocks will be lost when the app is terminated. Background sessions may prefer to use `-setDownloadTaskDidFinishDownloadingBlock:` to specify the URL for saving the downloaded file, rather than the destination block of this method. @warning If using a background `NSURLSessionConfiguration` on iOS, these blocks will be lost when the app is terminated. Background sessions may prefer to use `-setDownloadTaskDidFinishDownloadingBlock:` to specify the URL for saving the downloaded file, rather than the destination block of this method.
*/ */
- (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request - (NSURLSessionDownloadTask *)downloadTaskWithRequest:(NSURLRequest *)request
progress:(nullable void (^)(NSProgress *downloadProgress)) downloadProgressBlock progress:(nullable void (^)(NSProgress *downloadProgress))downloadProgressBlock
destination:(nullable NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination destination:(nullable NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
completionHandler:(nullable void (^)(NSURLResponse *response, NSURL * _Nullable filePath, NSError * _Nullable error))completionHandler; completionHandler:(nullable void (^)(NSURLResponse *response, NSURL * _Nullable filePath, NSError * _Nullable error))completionHandler;
@@ -288,12 +289,12 @@ NS_ASSUME_NONNULL_BEGIN
Creates an `NSURLSessionDownloadTask` with the specified resume data. Creates an `NSURLSessionDownloadTask` with the specified resume data.
@param resumeData The data used to resume downloading. @param resumeData The data used to resume downloading.
@param progress A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue. @param downloadProgressBlock A block object to be executed when the download progress is updated. Note this block is called on the session queue, not the main queue.
@param destination A block object to be executed in order to determine the destination of the downloaded file. This block takes two arguments, the target path & the server response, and returns the desired file URL of the resulting download. The temporary file used during the download will be automatically deleted after being moved to the returned URL. @param destination A block object to be executed in order to determine the destination of the downloaded file. This block takes two arguments, the target path & the server response, and returns the desired file URL of the resulting download. The temporary file used during the download will be automatically deleted after being moved to the returned URL.
@param completionHandler A block to be executed when a task finishes. This block has no return value and takes three arguments: the server response, the path of the downloaded file, and the error describing the network or parsing error that occurred, if any. @param completionHandler A block to be executed when a task finishes. This block has no return value and takes three arguments: the server response, the path of the downloaded file, and the error describing the network or parsing error that occurred, if any.
*/ */
- (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData - (NSURLSessionDownloadTask *)downloadTaskWithResumeData:(NSData *)resumeData
progress:(nullable void (^)(NSProgress *downloadProgress)) downloadProgressBlock progress:(nullable void (^)(NSProgress *downloadProgress))downloadProgressBlock
destination:(nullable NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination destination:(nullable NSURL * (^)(NSURL *targetPath, NSURLResponse *response))destination
completionHandler:(nullable void (^)(NSURLResponse *response, NSURL * _Nullable filePath, NSError * _Nullable error))completionHandler; completionHandler:(nullable void (^)(NSURLResponse *response, NSURL * _Nullable filePath, NSError * _Nullable error))completionHandler;
+7 -12
View File
@@ -1,5 +1,5 @@
// AFURLSessionManager.m // AFURLSessionManager.m
// Copyright (c) 20112016 Alamofire Software Foundation (http://alamofire.org/) // Copyright (c) 20112016 Alamofire Software Foundation ( http://alamofire.org/ )
// //
// Permission is hereby granted, free of charge, to any person obtaining a copy // Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal // of this software and associated documentation files (the "Software"), to deal
@@ -85,8 +85,6 @@ static NSString * const AFURLSessionManagerLockName = @"com.alamofire.networking
static NSUInteger const AFMaximumNumberOfAttemptsToRecreateBackgroundSessionUploadTask = 3; static NSUInteger const AFMaximumNumberOfAttemptsToRecreateBackgroundSessionUploadTask = 3;
static void * AFTaskStateChangedContext = &AFTaskStateChangedContext;
typedef void (^AFURLSessionDidBecomeInvalidBlock)(NSURLSession *session, NSError *error); typedef void (^AFURLSessionDidBecomeInvalidBlock)(NSURLSession *session, NSError *error);
typedef NSURLSessionAuthChallengeDisposition (^AFURLSessionDidReceiveAuthenticationChallengeBlock)(NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * __autoreleasing *credential); typedef NSURLSessionAuthChallengeDisposition (^AFURLSessionDidReceiveAuthenticationChallengeBlock)(NSURLSession *session, NSURLAuthenticationChallenge *challenge, NSURLCredential * __autoreleasing *credential);
@@ -224,13 +222,13 @@ typedef void (^AFURLSessionTaskCompletionHandler)(NSURLResponse *response, id re
- (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context { - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary<NSString *,id> *)change context:(void *)context {
if ([object isKindOfClass:[NSURLSessionTask class]] || [object isKindOfClass:[NSURLSessionDownloadTask class]]) { if ([object isKindOfClass:[NSURLSessionTask class]] || [object isKindOfClass:[NSURLSessionDownloadTask class]]) {
if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesReceived))]) { if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesReceived))]) {
self.downloadProgress.completedUnitCount = [change[@"new"] longLongValue]; self.downloadProgress.completedUnitCount = [change[NSKeyValueChangeNewKey] longLongValue];
} else if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesExpectedToReceive))]) { } else if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesExpectedToReceive))]) {
self.downloadProgress.totalUnitCount = [change[@"new"] longLongValue]; self.downloadProgress.totalUnitCount = [change[NSKeyValueChangeNewKey] longLongValue];
} else if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesSent))]) { } else if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesSent))]) {
self.uploadProgress.completedUnitCount = [change[@"new"] longLongValue]; self.uploadProgress.completedUnitCount = [change[NSKeyValueChangeNewKey] longLongValue];
} else if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesExpectedToSend))]) { } else if ([keyPath isEqualToString:NSStringFromSelector(@selector(countOfBytesExpectedToSend))]) {
self.uploadProgress.totalUnitCount = [change[@"new"] longLongValue]; self.uploadProgress.totalUnitCount = [change[NSKeyValueChangeNewKey] longLongValue];
} }
} }
else if ([object isEqual:self.downloadProgress]) { else if ([object isEqual:self.downloadProgress]) {
@@ -251,8 +249,6 @@ typedef void (^AFURLSessionTaskCompletionHandler)(NSURLResponse *response, id re
task:(NSURLSessionTask *)task task:(NSURLSessionTask *)task
didCompleteWithError:(NSError *)error didCompleteWithError:(NSError *)error
{ {
#pragma clang diagnostic push
#pragma clang diagnostic ignored "-Wgnu"
__strong AFURLSessionManager *manager = self.manager; __strong AFURLSessionManager *manager = self.manager;
__block id responseObject = nil; __block id responseObject = nil;
@@ -314,7 +310,6 @@ didCompleteWithError:(NSError *)error
}); });
}); });
} }
#pragma clang diagnostic pop
} }
#pragma mark - NSURLSessionDataTaskDelegate #pragma mark - NSURLSessionDataTaskDelegate
@@ -983,7 +978,7 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
disposition = NSURLSessionAuthChallengePerformDefaultHandling; disposition = NSURLSessionAuthChallengePerformDefaultHandling;
} }
} else { } else {
disposition = NSURLSessionAuthChallengeRejectProtectionSpace; disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge;
} }
} else { } else {
disposition = NSURLSessionAuthChallengePerformDefaultHandling; disposition = NSURLSessionAuthChallengePerformDefaultHandling;
@@ -1030,7 +1025,7 @@ didReceiveChallenge:(NSURLAuthenticationChallenge *)challenge
disposition = NSURLSessionAuthChallengeUseCredential; disposition = NSURLSessionAuthChallengeUseCredential;
credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust]; credential = [NSURLCredential credentialForTrust:challenge.protectionSpace.serverTrust];
} else { } else {
disposition = NSURLSessionAuthChallengeRejectProtectionSpace; disposition = NSURLSessionAuthChallengeCancelAuthenticationChallenge;
} }
} else { } else {
disposition = NSURLSessionAuthChallengePerformDefaultHandling; disposition = NSURLSessionAuthChallengePerformDefaultHandling;
+5 -2
View File
@@ -6,10 +6,13 @@
- (void)enableSSLPinning:(CDVInvokedUrlCommand*)command; - (void)enableSSLPinning:(CDVInvokedUrlCommand*)command;
- (void)acceptAllCerts:(CDVInvokedUrlCommand*)command; - (void)acceptAllCerts:(CDVInvokedUrlCommand*)command;
- (void)validateDomainName:(CDVInvokedUrlCommand*)command; - (void)disableRedirect:(CDVInvokedUrlCommand*)command;
- (void)post:(CDVInvokedUrlCommand*)command; - (void)post:(CDVInvokedUrlCommand*)command;
- (void)get:(CDVInvokedUrlCommand*)command; - (void)get:(CDVInvokedUrlCommand*)command;
- (void)put:(CDVInvokedUrlCommand*)command;
- (void)patch:(CDVInvokedUrlCommand*)command;
- (void)delete:(CDVInvokedUrlCommand*)command;
- (void)uploadFile:(CDVInvokedUrlCommand*)command; - (void)uploadFile:(CDVInvokedUrlCommand*)command;
- (void)downloadFile:(CDVInvokedUrlCommand*)command; - (void)downloadFile:(CDVInvokedUrlCommand*)command;
@end @end
+251 -52
View File
@@ -6,62 +6,136 @@
@interface CordovaHttpPlugin() @interface CordovaHttpPlugin()
- (void)setRequestHeaders:(NSDictionary*)headers forManager:(AFHTTPSessionManager*)manager; - (void)setRequestHeaders:(NSDictionary*)headers forManager:(AFHTTPSessionManager*)manager;
- (void)setResults:(NSMutableDictionary*)dictionary withTask:(NSURLSessionTask*)task; - (void)handleSuccess:(NSMutableDictionary*)dictionary withResponse:(NSHTTPURLResponse*)response andData:(id)data;
- (void)handleError:(NSMutableDictionary*)dictionary withResponse:(NSHTTPURLResponse*)response error:(NSError*)error;
- (NSNumber*)getStatusCode:(NSError*) error;
- (NSMutableDictionary*)copyHeaderFields:(NSDictionary*)headerFields;
- (void)setTimeout:(NSTimeInterval)timeout forManager:(AFHTTPSessionManager*)manager;
- (void)setRedirect:(AFHTTPSessionManager*)manager;
@end @end
@implementation CordovaHttpPlugin { @implementation CordovaHttpPlugin {
AFSecurityPolicy *securityPolicy; AFSecurityPolicy *securityPolicy;
bool redirect;
} }
- (void)pluginInitialize { - (void)pluginInitialize {
securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
redirect = true;
}
- (void)setRequestSerializer:(NSString*)serializerName forManager:(AFHTTPSessionManager*)manager {
if ([serializerName isEqualToString:@"json"]) {
manager.requestSerializer = [AFJSONRequestSerializer serializer];
} else {
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
}
} }
- (void)setRequestHeaders:(NSDictionary*)headers forManager:(AFHTTPSessionManager*)manager { - (void)setRequestHeaders:(NSDictionary*)headers forManager:(AFHTTPSessionManager*)manager {
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
[headers enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) { [headers enumerateKeysAndObjectsUsingBlock:^(id key, id obj, BOOL *stop) {
[manager.requestSerializer setValue:obj forHTTPHeaderField:key]; [manager.requestSerializer setValue:obj forHTTPHeaderField:key];
}]; }];
} }
- (void)setResults:(NSMutableDictionary*)dictionary withTask:(NSURLSessionTask*)task { - (void)setRedirect:(AFHTTPSessionManager*)manager {
if (task.response != nil) { [manager setTaskWillPerformHTTPRedirectionBlock:^NSURLRequest * _Nonnull(NSURLSession * _Nonnull session, NSURLSessionTask * _Nonnull task, NSURLResponse * _Nonnull response, NSURLRequest * _Nonnull request) {
NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response; if (redirect) {
return request;
} else {
return nil;
}
}];
}
- (void)handleSuccess:(NSMutableDictionary*)dictionary withResponse:(NSHTTPURLResponse*)response andData:(id)data {
if (response != nil) {
[dictionary setObject:[NSNumber numberWithInt:response.statusCode] forKey:@"status"]; [dictionary setObject:[NSNumber numberWithInt:response.statusCode] forKey:@"status"];
[dictionary setObject:response.allHeaderFields forKey:@"headers"]; [dictionary setObject:[self copyHeaderFields:response.allHeaderFields] forKey:@"headers"];
} }
if (data != nil) {
[dictionary setObject:data forKey:@"data"];
}
}
- (void)handleError:(NSMutableDictionary*)dictionary withResponse:(NSHTTPURLResponse*)response error:(NSError*)error {
if (response != nil) {
[dictionary setObject:[NSNumber numberWithInt:response.statusCode] forKey:@"status"];
[dictionary setObject:[self copyHeaderFields:response.allHeaderFields] forKey:@"headers"];
[dictionary setObject:[[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding] forKey:@"error"];
} else {
[dictionary setObject:[self getStatusCode:error] forKey:@"status"];
[dictionary setObject:[error localizedDescription] forKey:@"error"];
}
}
- (NSNumber*)getStatusCode:(NSError*) error {
switch ([error code]) {
case -1001:
// timeout
return [NSNumber numberWithInt:1];
case -1002:
// unsupported URL
return [NSNumber numberWithInt:2];
case -1003:
// server not found
return [NSNumber numberWithInt:0];
case -1009:
// no connection
return [NSNumber numberWithInt:3];
default:
return [NSNumber numberWithInt:-1];
}
}
- (NSMutableDictionary*)copyHeaderFields:(NSDictionary *)headerFields {
NSMutableDictionary *headerFieldsCopy = [[NSMutableDictionary alloc] initWithCapacity:headerFields.count];
NSString *headerKeyCopy;
for (NSString *headerKey in headerFields.allKeys) {
headerKeyCopy = [[headerKey mutableCopy] lowercaseString];
[headerFieldsCopy setValue:[headerFields objectForKey:headerKey] forKey:headerKeyCopy];
}
return headerFieldsCopy;
}
- (void)setTimeout:(NSTimeInterval)timeout forManager:(AFHTTPSessionManager*)manager {
[manager.requestSerializer setTimeoutInterval:timeout];
} }
- (void)enableSSLPinning:(CDVInvokedUrlCommand*)command { - (void)enableSSLPinning:(CDVInvokedUrlCommand*)command {
bool enable = [[command.arguments objectAtIndex:0] boolValue]; bool enable = [[command.arguments objectAtIndex:0] boolValue];
if (enable) { if (enable) {
securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate]; securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeCertificate];
} else { } else {
securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone]; securityPolicy = [AFSecurityPolicy policyWithPinningMode:AFSSLPinningModeNone];
} }
CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; CDVPluginResult* pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} }
- (void)disableRedirect:(CDVInvokedUrlCommand*)command {
CDVPluginResult* pluginResult = nil;
bool disable = [[command.arguments objectAtIndex:0] boolValue];
redirect = !disable;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
- (void)acceptAllCerts:(CDVInvokedUrlCommand*)command { - (void)acceptAllCerts:(CDVInvokedUrlCommand*)command {
CDVPluginResult* pluginResult = nil; CDVPluginResult* pluginResult = nil;
bool allow = [[command.arguments objectAtIndex:0] boolValue]; bool allow = [[command.arguments objectAtIndex:0] boolValue];
securityPolicy.allowInvalidCertificates = allow;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}
- (void)validateDomainName:(CDVInvokedUrlCommand*)command { securityPolicy.allowInvalidCertificates = allow;
CDVPluginResult* pluginResult = nil; securityPolicy.validatesDomainName = !allow;
bool validate = [[command.arguments objectAtIndex:0] boolValue];
securityPolicy.validatesDomainName = validate;
pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK]; pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK];
[self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [self.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} }
@@ -69,23 +143,30 @@
- (void)post:(CDVInvokedUrlCommand*)command { - (void)post:(CDVInvokedUrlCommand*)command {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.securityPolicy = securityPolicy; manager.securityPolicy = securityPolicy;
NSString *url = [command.arguments objectAtIndex:0]; NSString *url = [command.arguments objectAtIndex:0];
NSDictionary *parameters = [command.arguments objectAtIndex:1]; NSDictionary *parameters = [command.arguments objectAtIndex:1];
NSDictionary *headers = [command.arguments objectAtIndex:2]; NSString *serializerName = [command.arguments objectAtIndex:2];
NSDictionary *headers = [command.arguments objectAtIndex:3];
NSTimeInterval timeoutInSeconds = [[command.arguments objectAtIndex:4] doubleValue];
[self setRequestSerializer: serializerName forManager: manager];
[self setRequestHeaders: headers forManager: manager]; [self setRequestHeaders: headers forManager: manager];
[self setTimeout:timeoutInSeconds forManager:manager];
[self setRedirect: manager];
CordovaHttpPlugin* __weak weakSelf = self; CordovaHttpPlugin* __weak weakSelf = self;
manager.responseSerializer = [TextResponseSerializer serializer]; manager.responseSerializer = [TextResponseSerializer serializer];
[manager POST:url parameters:parameters progress:nil success:^(NSURLSessionTask *task, id responseObject) { [manager POST:url parameters:parameters progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self setResults: dictionary withTask: task]; [self handleSuccess:dictionary withResponse:(NSHTTPURLResponse*)task.response andData:responseObject];
[dictionary setObject:responseObject forKey:@"data"];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} failure:^(NSURLSessionTask *task, NSError *error) { } failure:^(NSURLSessionTask *task, NSError *error) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self setResults: dictionary withTask: task]; [self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
[dictionary setObject:[error localizedDescription] forKey:@"error"];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}]; }];
@@ -94,24 +175,127 @@
- (void)get:(CDVInvokedUrlCommand*)command { - (void)get:(CDVInvokedUrlCommand*)command {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.securityPolicy = securityPolicy; manager.securityPolicy = securityPolicy;
NSString *url = [command.arguments objectAtIndex:0]; NSString *url = [command.arguments objectAtIndex:0];
NSDictionary *parameters = [command.arguments objectAtIndex:1]; NSDictionary *parameters = [command.arguments objectAtIndex:1];
NSDictionary *headers = [command.arguments objectAtIndex:2]; NSDictionary *headers = [command.arguments objectAtIndex:2];
NSTimeInterval timeoutInSeconds = [[command.arguments objectAtIndex:3] doubleValue];
[self setRequestSerializer: @"default" forManager: manager];
[self setRequestHeaders: headers forManager: manager]; [self setRequestHeaders: headers forManager: manager];
[self setTimeout:timeoutInSeconds forManager:manager];
[self setRedirect: manager];
CordovaHttpPlugin* __weak weakSelf = self; CordovaHttpPlugin* __weak weakSelf = self;
manager.responseSerializer = [TextResponseSerializer serializer]; manager.responseSerializer = [TextResponseSerializer serializer];
[manager GET:url parameters:parameters progress:nil success:^(NSURLSessionTask *task, id responseObject) { [manager GET:url parameters:parameters progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self setResults: dictionary withTask: task]; [self handleSuccess:dictionary withResponse:(NSHTTPURLResponse*)task.response andData:responseObject];
[dictionary setObject:responseObject forKey:@"data"];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} failure:^(NSURLSessionTask *task, NSError *error) { } failure:^(NSURLSessionTask *task, NSError *error) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self setResults: dictionary withTask: task]; [self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
[dictionary setObject:[error localizedDescription] forKey:@"error"];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
- (void)put:(CDVInvokedUrlCommand*)command {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.securityPolicy = securityPolicy;
NSString *url = [command.arguments objectAtIndex:0];
NSDictionary *parameters = [command.arguments objectAtIndex:1];
NSString *serializerName = [command.arguments objectAtIndex:2];
NSDictionary *headers = [command.arguments objectAtIndex:3];
NSTimeInterval timeoutInSeconds = [[command.arguments objectAtIndex:4] doubleValue];
[self setRequestSerializer: serializerName forManager: manager];
[self setRequestHeaders: headers forManager: manager];
[self setTimeout:timeoutInSeconds forManager:manager];
[self setRedirect: manager];
CordovaHttpPlugin* __weak weakSelf = self;
manager.responseSerializer = [TextResponseSerializer serializer];
[manager PUT:url parameters:parameters success:^(NSURLSessionTask *task, id responseObject) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self handleSuccess:dictionary withResponse:(NSHTTPURLResponse*)task.response andData:responseObject];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} failure:^(NSURLSessionTask *task, NSError *error) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
- (void)patch:(CDVInvokedUrlCommand*)command {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.securityPolicy = securityPolicy;
NSString *url = [command.arguments objectAtIndex:0];
NSDictionary *parameters = [command.arguments objectAtIndex:1];
NSString *serializerName = [command.arguments objectAtIndex:2];
NSDictionary *headers = [command.arguments objectAtIndex:3];
NSTimeInterval timeoutInSeconds = [[command.arguments objectAtIndex:4] doubleValue];
[self setRequestSerializer: serializerName forManager: manager];
[self setRequestHeaders: headers forManager: manager];
[self setTimeout:timeoutInSeconds forManager:manager];
[self setRedirect: manager];
CordovaHttpPlugin* __weak weakSelf = self;
manager.responseSerializer = [TextResponseSerializer serializer];
[manager PATCH:url parameters:parameters success:^(NSURLSessionTask *task, id responseObject) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self handleSuccess:dictionary withResponse:(NSHTTPURLResponse*)task.response andData:responseObject];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} failure:^(NSURLSessionTask *task, NSError *error) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}];
}
- (void)delete:(CDVInvokedUrlCommand*)command {
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];
NSTimeInterval timeoutInSeconds = [[command.arguments objectAtIndex:3] doubleValue];
[self setRequestSerializer: @"default" forManager: manager];
[self setRequestHeaders: headers forManager: manager];
[self setTimeout:timeoutInSeconds forManager:manager];
[self setRedirect: manager];
CordovaHttpPlugin* __weak weakSelf = self;
manager.responseSerializer = [TextResponseSerializer serializer];
[manager DELETE:url parameters:parameters success:^(NSURLSessionTask *task, id responseObject) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self handleSuccess:dictionary withResponse:(NSHTTPURLResponse*)task.response andData:responseObject];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} failure:^(NSURLSessionTask *task, NSError *error) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}]; }];
@@ -123,21 +307,26 @@
NSString *url = [command.arguments objectAtIndex:0]; NSString *url = [command.arguments objectAtIndex:0];
NSDictionary *parameters = [command.arguments objectAtIndex:1]; NSDictionary *parameters = [command.arguments objectAtIndex:1];
NSDictionary *headers = [command.arguments objectAtIndex:2]; NSDictionary *headers = [command.arguments objectAtIndex:2];
NSTimeInterval timeoutInSeconds = [[command.arguments objectAtIndex:3] doubleValue];
[self setRequestHeaders: headers forManager: manager]; [self setRequestHeaders: headers forManager: manager];
[self setTimeout:timeoutInSeconds forManager:manager];
[self setRedirect: manager];
CordovaHttpPlugin* __weak weakSelf = self; CordovaHttpPlugin* __weak weakSelf = self;
manager.responseSerializer = [AFHTTPResponseSerializer serializer]; manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager HEAD:url parameters:parameters success:^(NSURLSessionTask *task) { [manager HEAD:url parameters:parameters success:^(NSURLSessionTask *task) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self setResults: dictionary withTask: task];
// no 'body' for HEAD request, omitting 'data' // no 'body' for HEAD request, omitting 'data'
[self handleSuccess:dictionary withResponse:(NSHTTPURLResponse*)task.response andData:nil];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} failure:^(NSURLSessionTask *task, NSError *error) { } failure:^(NSURLSessionTask *task, NSError *error) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self setResults: dictionary withTask: task]; [self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
[dictionary setObject:[error localizedDescription] forKey:@"error"];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}]; }];
@@ -146,16 +335,20 @@
- (void)uploadFile:(CDVInvokedUrlCommand*)command { - (void)uploadFile:(CDVInvokedUrlCommand*)command {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.securityPolicy = securityPolicy; manager.securityPolicy = securityPolicy;
NSString *url = [command.arguments objectAtIndex:0]; NSString *url = [command.arguments objectAtIndex:0];
NSDictionary *parameters = [command.arguments objectAtIndex:1]; NSDictionary *parameters = [command.arguments objectAtIndex:1];
NSDictionary *headers = [command.arguments objectAtIndex:2]; NSDictionary *headers = [command.arguments objectAtIndex:2];
NSString *filePath = [command.arguments objectAtIndex: 3]; NSString *filePath = [command.arguments objectAtIndex: 3];
NSString *name = [command.arguments objectAtIndex: 4]; NSString *name = [command.arguments objectAtIndex: 4];
NSTimeInterval timeoutInSeconds = [[command.arguments objectAtIndex:5] doubleValue];
NSURL *fileURL = [NSURL URLWithString: filePath]; NSURL *fileURL = [NSURL URLWithString: filePath];
[self setRequestHeaders: headers forManager: manager]; [self setRequestHeaders: headers forManager: manager];
[self setTimeout:timeoutInSeconds forManager:manager];
[self setRedirect: manager];
CordovaHttpPlugin* __weak weakSelf = self; CordovaHttpPlugin* __weak weakSelf = self;
manager.responseSerializer = [TextResponseSerializer serializer]; manager.responseSerializer = [TextResponseSerializer serializer];
[manager POST:url parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) { [manager POST:url parameters:parameters constructingBodyWithBlock:^(id<AFMultipartFormData> formData) {
@@ -171,13 +364,14 @@
} }
} progress:nil success:^(NSURLSessionTask *task, id responseObject) { } progress:nil success:^(NSURLSessionTask *task, id responseObject) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self setResults: dictionary withTask: task]; [self handleSuccess:dictionary withResponse:(NSHTTPURLResponse*)task.response andData:nil];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} failure:^(NSURLSessionTask *task, NSError *error) { } failure:^(NSURLSessionTask *task, NSError *error) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self setResults: dictionary withTask: task]; [self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
[dictionary setObject:[error localizedDescription] forKey:@"error"];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}]; }];
@@ -187,17 +381,21 @@
- (void)downloadFile:(CDVInvokedUrlCommand*)command { - (void)downloadFile:(CDVInvokedUrlCommand*)command {
AFHTTPSessionManager *manager = [AFHTTPSessionManager manager]; AFHTTPSessionManager *manager = [AFHTTPSessionManager manager];
manager.securityPolicy = securityPolicy; manager.securityPolicy = securityPolicy;
NSString *url = [command.arguments objectAtIndex:0]; NSString *url = [command.arguments objectAtIndex:0];
NSDictionary *parameters = [command.arguments objectAtIndex:1]; NSDictionary *parameters = [command.arguments objectAtIndex:1];
NSDictionary *headers = [command.arguments objectAtIndex:2]; NSDictionary *headers = [command.arguments objectAtIndex:2];
NSString *filePath = [command.arguments objectAtIndex: 3]; NSString *filePath = [command.arguments objectAtIndex: 3];
NSTimeInterval timeoutInSeconds = [[command.arguments objectAtIndex:4] doubleValue];
[self setRequestHeaders: headers forManager: manager]; [self setRequestHeaders: headers forManager: manager];
[self setTimeout:timeoutInSeconds forManager:manager];
[self setRedirect: manager];
if ([filePath hasPrefix:@"file://"]) { if ([filePath hasPrefix:@"file://"]) {
filePath = [filePath substringFromIndex:7]; filePath = [filePath substringFromIndex:7];
} }
CordovaHttpPlugin* __weak weakSelf = self; CordovaHttpPlugin* __weak weakSelf = self;
manager.responseSerializer = [AFHTTPResponseSerializer serializer]; manager.responseSerializer = [AFHTTPResponseSerializer serializer];
[manager GET:url parameters:parameters progress:nil success:^(NSURLSessionTask *task, id responseObject) { [manager GET:url parameters:parameters progress:nil success:^(NSURLSessionTask *task, id responseObject) {
@@ -222,10 +420,10 @@
* *
* Modified by Andrew Stephan for Sync OnSet * Modified by Andrew Stephan for Sync OnSet
* *
*/ */
// Download response is okay; begin streaming output to file // Download response is okay; begin streaming output to file
NSString* parentPath = [filePath stringByDeletingLastPathComponent]; NSString* parentPath = [filePath stringByDeletingLastPathComponent];
// create parent directories if needed // create parent directories if needed
NSError *error; NSError *error;
if ([[NSFileManager defaultManager] createDirectoryAtPath:parentPath withIntermediateDirectories:YES attributes:nil error:&error] == NO) { if ([[NSFileManager defaultManager] createDirectoryAtPath:parentPath withIntermediateDirectories:YES attributes:nil error:&error] == NO) {
@@ -249,17 +447,18 @@
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
return; return;
} }
id filePlugin = [self.commandDelegate getCommandInstance:@"File"]; id filePlugin = [self.commandDelegate getCommandInstance:@"File"];
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self setResults: dictionary withTask: task]; [self handleSuccess:dictionary withResponse:(NSHTTPURLResponse*)task.response andData:nil];
[dictionary setObject:[filePlugin getDirectoryEntry:filePath isDirectory:NO] forKey:@"file"]; [dictionary setObject:[filePlugin getDirectoryEntry:filePath isDirectory:NO] forKey:@"file"];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_OK messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
} failure:^(NSURLSessionTask *task, NSError *error) { } failure:^(NSURLSessionTask *task, NSError *error) {
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary]; NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
[self setResults: dictionary withTask: task]; [self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
[dictionary setObject:[error localizedDescription] forKey:@"error"];
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary]; CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId]; [weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
}]; }];
+6 -6
View File
@@ -1,10 +1,10 @@
#import "TextResponseSerializer.h" #import "TextResponseSerializer.h"
static BOOL AFErrorOrUnderlyingErrorHasCode(NSError *error, NSInteger code) { static BOOL AFErrorOrUnderlyingErrorHasCodeInDomain(NSError *error, NSInteger code, NSString *domain) {
if (error.code == code) { if ([error.domain isEqualToString:domain] && error.code == code) {
return YES; return YES;
} else if (error.userInfo[NSUnderlyingErrorKey]) { } else if (error.userInfo[NSUnderlyingErrorKey]) {
return AFErrorOrUnderlyingErrorHasCode(error.userInfo[NSUnderlyingErrorKey], code); return AFErrorOrUnderlyingErrorHasCodeInDomain(error.userInfo[NSUnderlyingErrorKey], code, domain);
} }
return NO; return NO;
@@ -23,7 +23,7 @@ static BOOL AFErrorOrUnderlyingErrorHasCode(NSError *error, NSInteger code) {
return nil; return nil;
} }
self.acceptableContentTypes = [NSSet setWithObjects:@"text/plain", @"text/html", @"text/json", @"application/json", @"text/xml", @"application/xml", @"text/css", nil]; self.acceptableContentTypes = [NSSet setWithObjects:@"text/plain", @"text/html", @"text/json", @"application/hal+json", @"application/json", @"text/xml", @"application/xml", @"text/css", nil];
return self; return self;
} }
@@ -35,7 +35,7 @@ static BOOL AFErrorOrUnderlyingErrorHasCode(NSError *error, NSInteger code) {
error:(NSError *__autoreleasing *)error error:(NSError *__autoreleasing *)error
{ {
if (![self validateResponse:(NSHTTPURLResponse *)response data:data error:error]) { if (![self validateResponse:(NSHTTPURLResponse *)response data:data error:error]) {
if (AFErrorOrUnderlyingErrorHasCode(*error, NSURLErrorCannotDecodeContentData)) { if (!error || AFErrorOrUnderlyingErrorHasCodeInDomain(*error, NSURLErrorCannotDecodeContentData, AFURLResponseSerializationErrorDomain)) {
return nil; return nil;
} }
} }
@@ -55,4 +55,4 @@ static BOOL AFErrorOrUnderlyingErrorHasCode(NSError *error, NSInteger code) {
return responseString; return responseString;
} }
@end @end
+27
View File
@@ -0,0 +1,27 @@
<?xml version='1.0' encoding='utf-8'?>
<widget id="com.ilkimen.http.demo" version="1.0.0" xmlns="http://www.w3.org/ns/widgets" xmlns:cdv="http://cordova.apache.org/ns/1.0">
<name>HttpDemo</name>
<description>
A sample Apache Cordova application that demonstrates advanced HTTP plugin.
</description>
<author email="dev@cordova.apache.org" href="http://cordova.io">
Sefa Ilkimen
</author>
<content src="index.html" />
<access origin="*" />
<allow-intent href="http://*/*" />
<allow-intent href="https://*/*" />
<allow-intent href="tel:*" />
<allow-intent href="sms:*" />
<allow-intent href="mailto:*" />
<allow-intent href="geo:*" />
<platform name="android">
<allow-intent href="market:*" />
</platform>
<platform name="ios">
<allow-intent href="itms:*" />
<allow-intent href="itms-apps:*" />
</platform>
<engine name="android" spec="6.2.3" />
<engine name="ios" spec="4.4.0" />
</widget>
+25
View File
@@ -0,0 +1,25 @@
{
"name": "com.ilkimen.http.demo",
"displayName": "HttpDemo",
"version": "1.0.0",
"description": "A sample Apache Cordova application that demonstrates advanced HTTP plugin.",
"main": "index.js",
"scripts": {
"build": "scripts/build.sh",
"test": "npm run build && scripts/test.sh"
},
"author": "Sefa Ilkimen",
"license": "Apache-2.0",
"dependencies": {
"cordova": "7.0.1",
"cordova-android": "6.2.3",
"cordova-ios": "4.4.0"
},
"cordova": {
"platforms": [
"android",
"ios"
]
},
"devDependencies": {}
}
+24
View File
@@ -0,0 +1,24 @@
* {
-webkit-tap-highlight-color: rgba(0,0,0,0); /* make transparent link selection, adjust last value opacity 0 to 1.0 */
}
body {
-webkit-touch-callout: none; /* prevent callout to copy image, etc when tap to hold */
-webkit-text-size-adjust: none; /* prevent webkit from resizing text to fit */
-webkit-user-select: none; /* prevent copy paste, to allow, change 'none' to 'text' */
height:100%;
margin:0px;
padding:20px 0;
width:100%;
font-family: sans-serif;
}
button, input, textarea {
display: block;
width: 100%;
}
h1 {
font-size: 12pt;
text-align: center;
}
Binary file not shown.

After

Width:  |  Height:  |  Size: 21 KiB

+20
View File
@@ -0,0 +1,20 @@
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Security-Policy" content="default-src 'self' data: gap: https://ssl.gstatic.com 'unsafe-eval'; style-src 'self' 'unsafe-inline'; media-src *; img-src 'self' data: content:;">
<meta name="format-detection" content="telephone=no">
<meta name="msapplication-tap-highlight" content="no">
<meta name="viewport" content="user-scalable=no, initial-scale=1, maximum-scale=1, minimum-scale=1, width=device-width">
<link rel="stylesheet" type="text/css" href="css/index.css">
</head>
<body>
<h1 id="descriptionLbl">Advanced HTTP test suite</h1>
<textarea rows="16" cols="50" id="expectedTextarea">Click next to run first test.</textarea>
<textarea rows="16" cols="50" id="resultTextarea"></textarea>
<button id="nextBtn">Run next test</button>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/test-definitions.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
</html>
+71
View File
@@ -0,0 +1,71 @@
const app = {
testIndex: -1,
initialize: function() {
document.getElementById('nextBtn').addEventListener('click', app.onNextBtnClick);
},
printResult: function(prefix, content) {
const text = prefix + ': ' + JSON.stringify(content);
document.getElementById('resultTextarea').value += text;
},
reject: function(content) {
app.printResult('result - rejected', content);
},
resolve: function(content) {
app.printResult('result - resolved', content);
},
runTest: function(index) {
const testDefinition = tests[index];
const titleText = app.testIndex + ': ' + testDefinition.description;
const expectedText = 'expected - ' + testDefinition.expected;
document.getElementById('expectedTextarea').value = expectedText;
document.getElementById('resultTextarea').value = '';
document.getElementById('descriptionLbl').innerText = titleText;
testDefinition.func(app.resolve, app.reject);
},
onBeforeTest: function(testIndex, cb) {
if (hooks && hooks.onBeforeEachTest) {
return hooks.onBeforeEachTest(function() {
const testDefinition = tests[testIndex];
if (testDefinition.before) {
testDefinition.before(cb);
} else {
cb();
}
});
} else {
cb();
}
},
onFinishedAllTests: function() {
const titleText = 'No more tests';
const expectedText = 'You have run all available tests.';
document.getElementById('expectedTextarea').value = expectedText;
document.getElementById('resultTextarea').value = '';
document.getElementById('descriptionLbl').innerText = titleText;
},
onNextBtnClick: function() {
app.testIndex += 1;
if (app.testIndex < tests.length) {
app.onBeforeTest(app.testIndex, function() {
app.runTest(app.testIndex);
});
} else {
app.onFinishedAllTests();
}
}
};
app.initialize();
+10
View File
@@ -0,0 +1,10 @@
const path = require('path');
if (process.env.SAUCE_USERNAME) {
exports.iosTestApp = 'sauce-storage:HttpDemo.app.zip';
exports.androidTestApp = 'sauce-storage:HttpDemo.apk';
} else {
// these paths are relative to working directory
exports.iosTestApp = path.resolve('temp/platforms/ios/build/emulator/HttpDemo.app');
exports.androidTestApp = path.resolve('temp/platforms/android/build/outputs/apk/android-debug.apk');
}
+65
View File
@@ -0,0 +1,65 @@
const local = {
iosDevice: {
browserName: '',
'appium-version': '1.7.1',
platformName: 'iOS',
platformVersion: '10.3',
deviceName: 'iPhone 6',
autoWebview: true,
app: undefined // will be set later
},
iosEmulator: {
browserName: '',
'appium-version': '1.7.1',
platformName: 'iOS',
platformVersion: '11.0',
deviceName: 'iPhone Simulator',
autoWebview: true,
app: undefined // will be set later
},
androidEmulator: {
browserName: '',
'appium-version': '1.7.1',
platformName: 'Android',
platformVersion: '5.1',
deviceName: 'Android Emulator',
autoWebview: true,
app: undefined // will be set later
}
};
const sauce = {
iosDevice: {
browserName: '',
'appium-version': '1.7.1',
platformName: 'iOS',
platformVersion: '10.3',
deviceName: 'iPhone 6',
autoWebview: true,
app: undefined // will be set later
},
iosEmulator: {
browserName: '',
'appium-version': '1.7.1',
platformName: 'iOS',
platformVersion: '10.3',
deviceName: 'iPhone Simulator',
autoWebview: true,
app: undefined // will be set later
},
androidEmulator: {
browserName: '',
'appium-version': '1.7.1',
platformName: 'Android',
platformVersion: '5.1',
deviceName: 'Android Emulator',
autoWebview: true,
app: undefined // will be set later
}
};
if (process.env.SAUCE_USERNAME) {
module.exports = sauce;
} else {
module.exports = local;
}
+13
View File
@@ -0,0 +1,13 @@
exports.configure = driver => {
driver.on('status', info => {
console.log(info.cyan);
});
driver.on('command', (meth, path, data) => {
console.log(' > ' + meth.yellow, path.grey, data || '');
});
driver.on('http', (meth, path, data) => {
console.log(' > ' + meth.magenta, path, (data || '').grey);
});
};
+16
View File
@@ -0,0 +1,16 @@
const local = {
host: 'localhost',
port: 4723
};
const sauce = {
host: 'ondemand.saucelabs.com',
port: 80,
auth: process.env.SAUCE_USERNAME + ":" + process.env.SAUCE_ACCESS_KEY
};
if (process.env.SAUCE_USERNAME) {
module.exports = sauce;
} else {
module.exports = local;
}
+12
View File
@@ -0,0 +1,12 @@
const wd = require("wd");
require('colors');
const chai = require('chai');
const chaiAsPromised = require('chai-as-promised');
chai.use(chaiAsPromised);
const should = chai.should();
chaiAsPromised.transferPromiseness = wd.transferPromiseness;
exports.should = should;
+73
View File
@@ -0,0 +1,73 @@
require('./helpers/setup');
const wd = require('wd');
const apps = require('./helpers/apps');
const caps = Object.assign({}, require('./helpers/caps'));
const serverConfig = require('./helpers/server');
const testDefinitions = require('../test-definitions');
const pkgjson = require('../../package.json');
describe('Advanced HTTP', function() {
let driver;
let allPassed = true;
this.timeout(900000);
const getCaps = appName => {
const isDevice = process.argv.includes('--device');
const isAndroid = process.argv.includes('--android');
const desiredCaps = caps[(isAndroid ? 'android' : 'ios') + (isDevice ? 'Device' : 'Emulator')];
const desiredApp = apps[(isAndroid ? 'android' : 'ios') + appName];
desiredCaps.name = pkgjson.name;
desiredCaps.app = desiredApp;
return desiredCaps;
};
const validateTestIndex = number => driver
.elementById('descriptionLbl')
.text()
.then(text => parseInt(text.match(/(\d+):/)[1], 10))
.should.eventually.become(number, 'Test index is not matching!');
const validateTestTitle = testTitle => driver
.elementById('descriptionLbl')
.text()
.then(text => text.match(/\d+:\ (.*)/)[1])
.should.eventually.become(testTitle, 'Test description is not matching!');
const validateResult = text => driver
.elementById('resultTextarea')
.getAttribute('value')
.should.eventually.include(text);
const clickNext = () => driver
.elementById('nextBtn')
.click()
.sleep(1000);
before(() => {
driver = wd.promiseChainRemote(serverConfig);
require('./helpers/logging').configure(driver);
return driver.init(getCaps('TestApp'));
});
after(() => driver
.quit()
.finally(function () {
if (process.env.SAUCE_USERNAME) {
return driver.sauceJobStatus(allPassed);
}
}));
testDefinitions.tests.forEach((definition, index) => {
it(definition.description, function() {
return clickNext()
.then(() => validateTestIndex(index))
.then(() => validateTestTitle(this.test.title))
.then(() => validateResult(definition.expected))
});
});
});
+67
View File
@@ -0,0 +1,67 @@
const hooks = {
onBeforeEachTest: function(done) {
cordova.plugin.http.acceptAllCerts(false, done, done);
}
};
const helpers = {
acceptAllCerts: function(done) { cordova.plugin.http.acceptAllCerts(true, done, done); }
};
const tests = [
{
description: 'should reject self signed cert (GET)',
expected: 'rejected: {"status":-1,"error":"cancelled"}',
func: function(resolve, reject) { cordova.plugin.http.get('https://self-signed.badssl.com/', {}, {}, resolve, reject); }
},{
description: 'should reject self signed cert (PUT)',
expected: 'rejected: {"status":-1,"error":"cancelled"}',
func: function(resolve, reject) { cordova.plugin.http.put('https://self-signed.badssl.com/', { test: 'testString' }, {}, resolve, reject); }
},{
description: 'should reject self signed cert (POST)',
expected: 'rejected: {"status":-1,"error":"cancelled"}',
func: function(resolve, reject) { cordova.plugin.http.post('https://self-signed.badssl.com/', { test: 'testString' }, {}, resolve, reject); }
},{
description: 'should reject self signed cert (PATCH)',
expected: 'rejected: {"status":-1,"error":"cancelled"}',
func: function(resolve, reject) { cordova.plugin.http.patch('https://self-signed.badssl.com/', { test: 'testString' }, {}, resolve, reject); }
},{
description: 'should reject self signed cert (DELETE)',
expected: 'rejected: {"status":-1,"error":"cancelled"}',
func: function(resolve, reject) { cordova.plugin.http.delete('https://self-signed.badssl.com/', {}, {}, resolve, reject); }
},{
description: 'should accept bad cert (GET)',
expected: 'resolved: {\"status\":200,',
before: helpers.acceptAllCerts,
func: function(resolve, reject) { cordova.plugin.http.get('https://self-signed.badssl.com/', {}, {}, resolve, reject); }
},{
description: 'should accept bad cert (PUT)',
expected: 'rejected: {\"status\":405,', // will be rejected because PUT is not allowed
before: helpers.acceptAllCerts,
func: function(resolve, reject) { cordova.plugin.http.put('https://self-signed.badssl.com/', { test: 'testString' }, {}, resolve, reject); }
},{
description: 'should accept bad cert (POST)',
expected: 'rejected: {\"status\":405,', // will be rejected because POST is not allowed
before: helpers.acceptAllCerts,
func: function(resolve, reject) { cordova.plugin.http.post('https://self-signed.badssl.com/', { test: 'testString' }, {}, resolve, reject); }
},{
description: 'should accept bad cert (PATCH)',
expected: 'rejected: {\"status\":405,', // will be rejected because PATCH is not allowed
before: helpers.acceptAllCerts,
func: function(resolve, reject) { cordova.plugin.http.patch('https://self-signed.badssl.com/', { test: 'testString' }, {}, resolve, reject); }
},{
description: 'should accept bad cert (DELETE)',
expected: 'rejected: {\"status\":405,', // will be rejected because DELETE is not allowed
before: helpers.acceptAllCerts,
func: function(resolve, reject) { cordova.plugin.http.delete('https://self-signed.badssl.com/', {}, {}, resolve, reject); }
},{
description: 'should fetch data from http://google.com/ (GET)',
expected: 'resolved: {\"status\":200,',
before: helpers.acceptAllCerts,
func: function(resolve, reject) { cordova.plugin.http.get('http://google.com/', {}, {}, resolve, reject); }
}
];
if (module && module.exports) {
module.exports = { tests: tests, hooks: hooks };
}
+274
View File
@@ -0,0 +1,274 @@
/*global angular*/
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* Modified by Andrew Stephan for Sync OnSet
* Modified by Sefa Ilkimen:
* - added configurable params serializer
* - added put and delete methods
* - using cordova www module pattern
* - some minor improvements
*
*/
/*
* An HTTP Plugin for PhoneGap.
*/
var pluginId = module.id.slice(0, module.id.indexOf('.'));
var validSerializers = ['urlencoded', 'json'];
var exec = require('cordova/exec');
var angularIntegration = require(pluginId +'.angular-integration');
var cookieHandler = require(pluginId + '.cookie-handler');
// 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;
}
function checkSerializer(serializer) {
serializer = serializer || '';
serializer = serializer.trim().toLowerCase();
if (validSerializers.indexOf(serializer) > -1) {
return serializer;
}
return serializer[0];
}
function resolveCookieString(headers) {
var keys = Object.keys(headers || {});
for (var i = 0; i < keys.length; ++i) {
if (keys[i].match(/^set-cookie$/i)) {
return headers[keys[i]];
}
}
return null;
}
function createFileEntry(rawEntry) {
var entry = new (require('cordova-plugin-file.FileEntry'))();
entry.isDirectory = rawEntry.isDirectory;
entry.isFile = rawEntry.isFile;
entry.name = rawEntry.name;
entry.fullPath = rawEntry.fullPath;
entry.filesystem = new FileSystem(rawEntry.filesystemName || (rawEntry.filesystem == window.PERSISTENT ? 'persistent' : 'temporary'));
entry.nativeURL = rawEntry.nativeURL;
return entry;
}
function injectCookieHandler(url, cb) {
return function(response) {
cookieHandler.setCookieFromString(url, resolveCookieString(response.headers));
cb(response);
}
}
function injectFileEntryHandler(cb) {
return function(response) {
cb(createFileEntry(response.file));
}
}
function getCookieHeader(url) {
return { Cookie: cookieHandler.getCookieString(url) };
}
function handleMissingCallbacks(successFn, failFn) {
if (Object.prototype.toString.call(successFn) !== '[object Function]') {
throw new Error('advanced-http: missing mandatory "onSuccess" callback function');
}
if (Object.prototype.toString.call(failFn) !== '[object Function]') {
throw new Error('advanced-http: missing mandatory "onFail" callback function');
}
}
var http = {
headers: {},
dataSerializer: 'urlencoded',
sslPinning: false,
timeoutInSeconds: 60.0,
getBasicAuthHeader: function (username, password) {
return {'Authorization': 'Basic ' + b64EncodeUnicode(username + ':' + password)};
},
useBasicAuth: function (username, password) {
this.headers.Authorization = 'Basic ' + b64EncodeUnicode(username + ':' + password);
},
setHeader: function (header, value) {
this.headers[header] = value;
},
setDataSerializer: function (serializer) {
this.dataSerializer = checkSerializer(serializer);
},
clearCookies: function () {
return cookieHandler.clearCookies();
},
removeCookies: function (url, callback) {
cookieHandler.removeCookies(url, callback);
},
setRequestTimeout: function(timeout) {
this.timeoutInSeconds = timeout;
},
enableSSLPinning: function (enable, success, failure) {
return exec(success, failure, 'CordovaHttpPlugin', 'enableSSLPinning', [enable]);
},
acceptAllCerts: function (allow, success, failure) {
return exec(success, failure, 'CordovaHttpPlugin', 'acceptAllCerts', [allow]);
},
disableRedirect: function(disable, success, failure) {
return exec(success, failure, 'CordovaHttpPlugin', 'disableRedirect', [disable]);
},
validateDomainName: function (validate, success, failure) {
failure('advanced-http: "validateDomainName" is no more supported, please see change log for further info');
},
post: function (url, data, headers, success, failure) {
handleMissingCallbacks(success, failure);
data = data || {};
headers = headers || {};
headers = mergeHeaders(this.headers, headers);
headers = mergeHeaders(getCookieHeader(url), headers);
var onSuccess = injectCookieHandler(url, success);
var onFail = injectCookieHandler(url, failure);
return exec(onSuccess, onFail, 'CordovaHttpPlugin', 'post', [url, data, this.dataSerializer, headers, this.timeoutInSeconds]);
},
get: function (url, params, headers, success, failure) {
handleMissingCallbacks(success, failure);
params = params || {};
headers = headers || {};
headers = mergeHeaders(this.headers, headers);
headers = mergeHeaders(getCookieHeader(url), headers);
var onSuccess = injectCookieHandler(url, success);
var onFail = injectCookieHandler(url, failure);
return exec(onSuccess, onFail, 'CordovaHttpPlugin', 'get', [url, params, headers, this.timeoutInSeconds]);
},
put: function (url, data, headers, success, failure) {
handleMissingCallbacks(success, failure);
data = data || {};
headers = headers || {};
headers = mergeHeaders(this.headers, headers);
headers = mergeHeaders(getCookieHeader(url), headers);
var onSuccess = injectCookieHandler(url, success);
var onFail = injectCookieHandler(url, failure);
return exec(onSuccess, onFail, 'CordovaHttpPlugin', 'put', [url, data, this.dataSerializer, headers, this.timeoutInSeconds]);
},
patch: function (url, data, headers, success, failure) {
handleMissingCallbacks(success, failure);
data = data || {};
headers = headers || {};
headers = mergeHeaders(this.headers, headers);
headers = mergeHeaders(getCookieHeader(url), headers);
var onSuccess = injectCookieHandler(url, success);
var onFail = injectCookieHandler(url, failure);
return exec(onSuccess, onFail, 'CordovaHttpPlugin', 'patch', [url, data, this.dataSerializer, headers, this.timeoutInSeconds]);
},
delete: function (url, params, headers, success, failure) {
handleMissingCallbacks(success, failure);
params = params || {};
headers = headers || {};
headers = mergeHeaders(this.headers, headers);
headers = mergeHeaders(getCookieHeader(url), headers);
var onSuccess = injectCookieHandler(url, success);
var onFail = injectCookieHandler(url, failure);
return exec(onSuccess, onFail, 'CordovaHttpPlugin', 'delete', [url, params, headers, this.timeoutInSeconds]);
},
head: function (url, params, headers, success, failure) {
handleMissingCallbacks(success, failure);
params = params || {};
headers = headers || {};
headers = mergeHeaders(this.headers, headers);
headers = mergeHeaders(getCookieHeader(url), headers);
var onSuccess = injectCookieHandler(url, success);
var onFail = injectCookieHandler(url, failure);
return exec(onSuccess, onFail, 'CordovaHttpPlugin', 'head', [url, params, headers, this.timeoutInSeconds]);
},
uploadFile: function (url, params, headers, filePath, name, success, failure) {
handleMissingCallbacks(success, failure);
params = params || {};
headers = headers || {};
headers = mergeHeaders(this.headers, headers);
headers = mergeHeaders(getCookieHeader(url), headers);
var onSuccess = injectCookieHandler(url, success);
var onFail = injectCookieHandler(url, failure);
return exec(onSuccess, onFail, 'CordovaHttpPlugin', 'uploadFile', [url, params, headers, filePath, name, this.timeoutInSeconds]);
},
downloadFile: function (url, params, headers, filePath, success, failure) {
handleMissingCallbacks(success, failure);
params = params || {};
headers = headers || {};
headers = mergeHeaders(this.headers, headers);
headers = mergeHeaders(getCookieHeader(url), headers);
var onSuccess = injectCookieHandler(url, injectFileEntryHandler(success));
var onFail = injectCookieHandler(url, failure);
return exec(onSuccess, onFail, 'CordovaHttpPlugin', 'downloadFile', [url, params, headers, filePath, this.timeoutInSeconds]);
}
};
angularIntegration.registerService(http);
module.exports = http;
+96
View File
@@ -0,0 +1,96 @@
function registerService(http) {
if (typeof angular === 'undefined') return;
angular.module('cordovaHTTP', []).factory('cordovaHTTP', function ($timeout, $q) {
function makePromise(fn, args, async) {
var deferred = $q.defer();
var success = function (response) {
if (async) {
$timeout(function () {
deferred.resolve(response);
});
} else {
deferred.resolve(response);
}
};
var fail = function (response) {
if (async) {
$timeout(function () {
deferred.reject(response);
});
} else {
deferred.reject(response);
}
};
args.push(success);
args.push(fail);
fn.apply(http, args);
return deferred.promise;
}
var cordovaHTTP = {
getBasicAuthHeader: http.getBasicAuthHeader,
useBasicAuth: function (username, password) {
return http.useBasicAuth(username, password);
},
setHeader: function (header, value) {
return http.setHeader(header, value);
},
setDataSerializer: function (serializer) {
return http.setDataSerializer(serializer);
},
clearCookies: function () {
return http.clearCookies();
},
removeCookies: function (url) {
return http.removeCookies(url);
},
setRequestTimeout: function (timeout) {
return http.setRequestTimeout(timeout);
},
enableSSLPinning: function (enable) {
return makePromise(http.enableSSLPinning, [enable]);
},
acceptAllCerts: function (allow) {
return makePromise(http.acceptAllCerts, [allow]);
},
disableRedirect: function(disable) {
return makePromise(http.disableRedirect, [disable]);
},
validateDomainName: function (validate) {
return makePromise(http.validateDomainName, [validate]);
},
post: function (url, data, headers) {
return makePromise(http.post, [url, data, headers], true);
},
get: function (url, params, headers) {
return makePromise(http.get, [url, params, headers], true);
},
put: function (url, data, headers) {
return makePromise(http.put, [url, data, headers], true);
},
delete: function (url, params, headers) {
return makePromise(http.delete, [url, params, headers], true);
},
head: function (url, params, headers) {
return makePromise(http.head, [url, params, headers], true);
},
uploadFile: function (url, params, headers, filePath, name) {
return makePromise(http.uploadFile, [url, params, headers, filePath, name], true);
},
downloadFile: function (url, params, headers, filePath) {
return makePromise(http.downloadFile, [url, params, headers, filePath], true);
}
};
return cordovaHTTP;
});
}
module.exports = {
registerService: registerService
};
+66
View File
@@ -0,0 +1,66 @@
var pluginId = module.id.slice(0, module.id.indexOf('.'));
var ToughCookie = require(pluginId + '.tough-cookie');
var WebStorageCookieStore = require(pluginId + '.local-storage-store');
var storage = window.localStorage;
var storeKey = '__advancedHttpCookieStore__';
var store = new WebStorageCookieStore(storage, storeKey);
var cookieJar = new ToughCookie.CookieJar(store);
module.exports = {
setCookieFromString: setCookieFromString,
getCookieString: getCookieString,
clearCookies: clearCookies,
removeCookies: removeCookies
}
function splitCookieString(cookieStr) {
var cookieParts = cookieStr.split(',');
var splitCookies = [];
var processedCookie = null;
for (var i = 0; i < cookieParts.length; ++i) {
if (cookieParts[i].substr(-11, 8).toLowerCase() === 'expires=') {
processedCookie = cookieParts[i] + ',' + cookieParts[i + 1];
i++;
} else {
processedCookie = cookieParts[i];
}
processedCookie = processedCookie.trim();
splitCookies.push(processedCookie);
}
return splitCookies;
}
function setCookieFromString(url, cookieStr) {
if (!cookieStr) return;
var cookies = splitCookieString(cookieStr);
for (var i = 0; i < cookies.length; ++i) {
cookieJar.setCookieSync(cookies[i], url, { ignoreError: true });
}
}
function getCookieString(url) {
return cookieJar.getCookieStringSync(url);
}
function clearCookies() {
window.localStorage.removeItem(storeKey);
}
function removeCookies(url, cb) {
cookieJar.getCookies(url, function(error, cookies) {
if (!cookies || cookies.length === 0) {
return cb(null, []);
}
var domain = cookies[0].domain;
cookieJar.store.removeCookies(domain, null, cb);
});
}
-175
View File
@@ -1,175 +0,0 @@
/*global angular*/
/*
* An HTTP Plugin for PhoneGap.
*/
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 = {
headers: {},
sslPinning: false,
getBasicAuthHeader: function(username, password) {
return {'Authorization': 'Basic ' + b64EncodeUnicode(username + ':' + password)};
},
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]);
},
acceptAllCerts: function(allow, success, failure) {
return exec(success, failure, "CordovaHttpPlugin", "acceptAllCerts", [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) {
/*
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*
* 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;
entry.isFile = true;
entry.name = result.file.name;
entry.fullPath = result.file.fullPath;
entry.filesystem = new FileSystem(result.file.filesystemName || (result.file.filesystem == window.PERSISTENT ? 'persistent' : 'temporary'));
entry.nativeURL = result.file.nativeURL;
success(entry);
};
return exec(win, failure, "CordovaHttpPlugin", "downloadFile", [url, params, headers, filePath]);
}
};
module.exports = http;
if (typeof angular !== "undefined") {
angular.module('cordovaHTTP', []).factory('cordovaHTTP', function($timeout, $q) {
function makePromise(fn, args, async) {
var deferred = $q.defer();
var success = function(response) {
if (async) {
$timeout(function() {
deferred.resolve(response);
});
} else {
deferred.resolve(response);
}
};
var fail = function(response) {
if (async) {
$timeout(function() {
deferred.reject(response);
});
} else {
deferred.reject(response);
}
};
args.push(success);
args.push(fail);
fn.apply(http, args);
return deferred.promise;
}
var cordovaHTTP = {
getBasicAuthHeader: http.getBasicAuthHeader,
useBasicAuth: function(username, password) {
return http.useBasicAuth(username, password);
},
setHeader: function(header, value) {
return http.setHeader(header, value);
},
enableSSLPinning: function(enable) {
return makePromise(http.enableSSLPinning, [enable]);
},
acceptAllCerts: function(allow) {
return makePromise(http.acceptAllCerts, [allow]);
},
validateDomainName: function(validate) {
return makePromise(http.validateDomainName, [validate]);
},
post: function(url, params, headers) {
return makePromise(http.post, [url, params, headers], true);
},
get: function(url, params, headers) {
return makePromise(http.get, [url, params, headers], true);
},
head: function(url, params, headers) {
return makePromise(http.head, [url, params, headers], true);
},
uploadFile: function(url, params, headers, filePath, name) {
return makePromise(http.uploadFile, [url, params, headers, filePath, name], true);
},
downloadFile: function(url, params, headers, filePath) {
return makePromise(http.downloadFile, [url, params, headers, filePath], true);
}
};
return cordovaHTTP;
});
} else {
window.cordovaHTTP = http;
}
+183
View File
@@ -0,0 +1,183 @@
/*
* The MIT License (MIT)
*
* Copyright (c) 2016 Exponent
*
* 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.
*
* Based on "tough-cookie-web-storage-store" v1.0.0
* Thanks James Ide: https://github.com/exponentjs/tough-cookie-web-storage-store
*
* Modified by Sefa Ilkimen for cordova plugin integration
*
*/
'use strict';
var pluginId = module.id.slice(0, module.id.indexOf('.'));
var ToughCookie = require(pluginId + '.tough-cookie');
var _ = require(pluginId + '.lodash');
function WebStorageCookieStore(storage, storeKey) {
ToughCookie.Store.call(this);
this._storage = storage || window.localStorage;
this._storeKey = storeKey || '__cookieStore__';
this.synchronous = true;
}
WebStorageCookieStore.prototype = Object.create(ToughCookie.Store);
WebStorageCookieStore.prototype.findCookie = function(domain, path, key, callback) {
var store = this._readStore();
var cookie = _.get(store, [domain, path, key], null);
callback(null, ToughCookie.Cookie.fromJSON(cookie));
};
WebStorageCookieStore.prototype.findCookies = function(domain, path, callback) {
if (!domain) {
callback(null, []);
return;
}
var that = this;
var cookies = [];
var store = this._readStore();
var domains = ToughCookie.permuteDomain(domain) || [domain];
domains.forEach(function(domain) {
if (!store[domain]) {
return;
}
var matchingPaths = Object.keys(store[domain]);
if (path != null) {
matchingPaths = matchingPaths.filter(function(cookiePath) {
return that._isOnPath(cookiePath, path);
});
}
matchingPaths.forEach(function(path) {
Array.prototype.push.apply(cookies, _.values(store[domain][path]));
});
});
cookies = cookies.map(function(cookie) {
return ToughCookie.Cookie.fromJSON(cookie);
});
callback(null, cookies);
};
/**
* Returns whether `cookiePath` is on the given `urlPath`
*/
WebStorageCookieStore.prototype._isOnPath = function(cookiePath, urlPath) {
if (!cookiePath) {
return false;
}
if (cookiePath === urlPath) {
return true;
}
if (urlPath.indexOf(cookiePath) !== 0) {
return false;
}
if (cookiePath[cookiePath.length - 1] !== '/' && urlPath[cookiePath.length] !== '/') {
return false;
}
return true;
};
WebStorageCookieStore.prototype.putCookie = function(cookie, callback) {
var store = this._readStore();
_.set(store, [cookie.domain, cookie.path, cookie.key], cookie);
this._writeStore(store);
callback(null);
};
WebStorageCookieStore.prototype.updateCookie = function(oldCookie, newCookie, callback) {
this.putCookie(newCookie, callback);
};
WebStorageCookieStore.prototype.removeCookie = function(domain, path, key, callback) {
var store = this._readStore();
_.unset(store, [domain, path, key]);
this._writeStore(store);
callback(null);
};
WebStorageCookieStore.prototype.removeCookies = function(domain, path, callback) {
var store = this._readStore();
if (path == null) {
_.unset(store, [domain]);
} else {
_.unset(store, [domain, path]);
}
this._writeStore(store);
callback(null);
};
WebStorageCookieStore.prototype.getAllCookies = function(callback) {
var cookies = [];
var store = this._readStore();
Object.keys(store).forEach(function(domain) {
Object.keys(store[domain]).forEach(function(path) {
Array.protype.push.apply(cookies, _.values(store[domain][path]));
});
});
cookies = cookies.map(function(cookie) {
return ToughCookie.Cookie.fromJSON(cookie);
});
cookies.sort(function(c1, c2) {
return (c1.creationIndex || 0) - (c2.creationIndex || 0);
});
callback(null, cookies);
};
WebStorageCookieStore.prototype._readStore = function() {
var json = this._storage.getItem(this._storeKey);
if (json !== null) {
try {
return JSON.parse(json);
} catch (e) { }
}
return {};
};
WebStorageCookieStore.prototype._writeStore = function(store) {
this._storage.setItem(this._storeKey, JSON.stringify(store));
};
module.exports = WebStorageCookieStore;
+20
View File
@@ -0,0 +1,20 @@
/**
* @license
* Lodash (Custom Build) lodash.com/license | Underscore.js 1.8.3 underscorejs.org/LICENSE
* Build: `lodash include="get,set,unset,values" exports="node"`
*/
;(function(){function t(t,e){for(var r=-1,n=null==t?0:t.length,o=Array(n);++r<n;)o[r]=e(t[r],r,t);return o}function e(t){return function(e){return t(e)}}function r(e,r){return t(r,function(t){return e[t]})}function n(){}function o(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function u(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1])}}function i(t){var e=-1,r=null==t?0:t.length;for(this.clear();++e<r;){var n=t[e];this.set(n[0],n[1]);
}}function c(t,e){for(var r=t.length;r--;)if(m(t[r][0],e))return r;return-1}function a(t,e){e=h(e,t);for(var r=0,n=e.length;null!=t&&r<n;)t=t[j(e[r++])];return r&&r==n?t:E}function l(t){if(null==t)return t===E?"[object Undefined]":"[object Null]";t=Object(t);var e;if(nt&&nt in t){var r=Q.call(t,nt),n=t[nt];try{t[nt]=E,e=true}catch(t){}var o=Y.call(t);e&&(r?t[nt]=n:delete t[nt]),e=o}else e=Y.call(t);return e}function s(t){return w(t)&&"[object Arguments]"==l(t)}function f(t){return w(t)&&z(t.length)&&!!M[l(t)];
}function p(e){if(typeof e=="string")return e;if(ft(e))return t(e,p)+"";if(x(e))return at?at.call(e):"";var r=e+"";return"0"==r&&1/e==-T?"-0":r}function h(t,e){var r;return ft(t)?r=t:(ft(t)?r=false:(r=typeof t,r=!("number"!=r&&"symbol"!=r&&"boolean"!=r&&null!=t&&!x(t))||(B.test(t)||!I.test(t)||null!=e&&t in Object(e))),r=r?[t]:lt(F(t))),r}function y(t,e){var r=t.__data__,n=typeof e;return("string"==n||"number"==n||"symbol"==n||"boolean"==n?"__proto__"!==e:null===e)?r[typeof e=="string"?"string":"hash"]:r.map;
}function b(t,e){var r=null==t?E:t[e];return(!S(r)||X&&X in r?0:(O(r)?Z:L).test(g(r)))?r:E}function _(t,e){return e=null==e?9007199254740991:e,!!e&&(typeof t=="number"||R.test(t))&&-1<t&&0==t%1&&t<e}function j(t){if(typeof t=="string"||x(t))return t;var e=t+"";return"0"==e&&1/t==-T?"-0":e}function g(t){if(null!=t){try{return K.call(t)}catch(t){}return t+""}return""}function v(t){var e=null==t?0:t.length;return e?t[e-1]:E}function d(t,e){function r(){var n=arguments,o=e?e.apply(this,n):n[0],u=r.cache;
return u.has(o)?u.get(o):(n=t.apply(this,n),r.cache=u.set(o,n)||u,n)}if(typeof t!="function"||null!=e&&typeof e!="function")throw new TypeError("Expected a function");return r.cache=new(d.Cache||i),r}function m(t,e){return t===e||t!==t&&e!==e}function A(t){return null!=t&&z(t.length)&&!O(t)}function O(t){return!!S(t)&&(t=l(t),"[object Function]"==t||"[object GeneratorFunction]"==t||"[object AsyncFunction]"==t||"[object Proxy]"==t)}function z(t){return typeof t=="number"&&-1<t&&0==t%1&&9007199254740991>=t;
}function S(t){var e=typeof t;return null!=t&&("object"==e||"function"==e)}function w(t){return null!=t&&typeof t=="object"}function x(t){return typeof t=="symbol"||w(t)&&"[object Symbol]"==l(t)}function F(t){return null==t?"":p(t)}function $(t){if(A(t)){var e=ft(t),r=!e&&st(t),n=!e&&!r&&pt(t),o=!e&&!r&&!n&&ht(t);if(e=e||r||n||o){for(var r=t.length,u=String,i=-1,c=Array(r);++i<r;)c[i]=u(i);r=c}else r=[];var a,u=r.length;for(a in t)!Q.call(t,a)||e&&("length"==a||n&&("offset"==a||"parent"==a)||o&&("buffer"==a||"byteLength"==a||"byteOffset"==a)||_(a,u))||r.push(a);
t=r}else if(a=t&&t.constructor,t===(typeof a=="function"&&a.prototype||H)){a=[];for(n in Object(t))Q.call(t,n)&&"constructor"!=n&&a.push(n);t=a}else t=ut(t);return t}function k(){return false}var E,T=1/0,I=/\.|\[(?:[^[\]]*|(["'])(?:(?!\1)[^\\]|\\.)*?\1)\]/,B=/^\w*$/,P=/^\./,U=/[^.[\]]+|\[(?:(-?\d+(?:\.\d+)?)|(["'])((?:(?!\2)[^\\]|\\.)*?)\2)\]|(?=(?:\.|\[\])(?:\.|\[\]|$))/g,C=/\\(\\)?/g,L=/^\[object .+?Constructor\]$/,R=/^(?:0|[1-9]\d*)$/,M={};M["[object Float32Array]"]=M["[object Float64Array]"]=M["[object Int8Array]"]=M["[object Int16Array]"]=M["[object Int32Array]"]=M["[object Uint8Array]"]=M["[object Uint8ClampedArray]"]=M["[object Uint16Array]"]=M["[object Uint32Array]"]=true,
M["[object Arguments]"]=M["[object Array]"]=M["[object ArrayBuffer]"]=M["[object Boolean]"]=M["[object DataView]"]=M["[object Date]"]=M["[object Error]"]=M["[object Function]"]=M["[object Map]"]=M["[object Number]"]=M["[object Object]"]=M["[object RegExp]"]=M["[object Set]"]=M["[object String]"]=M["[object WeakMap]"]=false;var N,D=typeof global=="object"&&global&&global.Object===Object&&global,V=typeof self=="object"&&self&&self.Object===Object&&self,q=D||V||Function("return this")(),G=(V=typeof exports=="object"&&exports&&!exports.nodeType&&exports)&&typeof module=="object"&&module&&!module.nodeType&&module,W=G&&G.exports===V,D=W&&D.process;
t:{try{N=D&&D.binding&&D.binding("util");break t}catch(t){}N=void 0}N=N&&N.isTypedArray;var D=Array.prototype,H=Object.prototype,J=q["__core-js_shared__"],K=Function.prototype.toString,Q=H.hasOwnProperty,X=function(){var t=/[^.]+$/.exec(J&&J.keys&&J.keys.IE_PROTO||"");return t?"Symbol(src)_1."+t:""}(),Y=H.toString,Z=RegExp("^"+K.call(Q).replace(/[\\^$.*+?()[\]{}|]/g,"\\$&").replace(/hasOwnProperty|(function).*?(?=\\\()| for .+?(?=\\\])/g,"$1.*?")+"$"),tt=W?q.Buffer:E,W=q.Symbol,et=H.propertyIsEnumerable,rt=D.splice,nt=W?W.toStringTag:E,ot=function(){
try{var t=b(Object,"defineProperty");return t({},"",{}),t}catch(t){}}(),D=tt?tt.isBuffer:E,ut=function(t,e){return function(r){return t(e(r))}}(Object.keys,Object),it=b(q,"Map"),ct=b(Object,"create"),at=(q=W?W.prototype:E)?q.toString:E;o.prototype.clear=function(){this.__data__=ct?ct(null):{},this.size=0},o.prototype.delete=function(t){return t=this.has(t)&&delete this.__data__[t],this.size-=t?1:0,t},o.prototype.get=function(t){var e=this.__data__;return ct?(t=e[t],"__lodash_hash_undefined__"===t?E:t):Q.call(e,t)?e[t]:E;
},o.prototype.has=function(t){var e=this.__data__;return ct?e[t]!==E:Q.call(e,t)},o.prototype.set=function(t,e){var r=this.__data__;return this.size+=this.has(t)?0:1,r[t]=ct&&e===E?"__lodash_hash_undefined__":e,this},u.prototype.clear=function(){this.__data__=[],this.size=0},u.prototype.delete=function(t){var e=this.__data__;return t=c(e,t),!(0>t)&&(t==e.length-1?e.pop():rt.call(e,t,1),--this.size,true)},u.prototype.get=function(t){var e=this.__data__;return t=c(e,t),0>t?E:e[t][1]},u.prototype.has=function(t){
return-1<c(this.__data__,t)},u.prototype.set=function(t,e){var r=this.__data__,n=c(r,t);return 0>n?(++this.size,r.push([t,e])):r[n][1]=e,this},i.prototype.clear=function(){this.size=0,this.__data__={hash:new o,map:new(it||u),string:new o}},i.prototype.delete=function(t){return t=y(this,t).delete(t),this.size-=t?1:0,t},i.prototype.get=function(t){return y(this,t).get(t)},i.prototype.has=function(t){return y(this,t).has(t)},i.prototype.set=function(t,e){var r=y(this,t),n=r.size;return r.set(t,e),this.size+=r.size==n?0:1,
this};var lt=function(t){t=d(t,function(t){return 500===e.size&&e.clear(),t});var e=t.cache;return t}(function(t){var e=[];return P.test(t)&&e.push(""),t.replace(U,function(t,r,n,o){e.push(n?o.replace(C,"$1"):r||t)}),e});d.Cache=i;var st=s(function(){return arguments}())?s:function(t){return w(t)&&Q.call(t,"callee")&&!et.call(t,"callee")},ft=Array.isArray,pt=D||k,ht=N?e(N):f;n.keys=$,n.memoize=d,n.set=function(t,e,r){if(null!=t&&S(t)){e=h(e,t);for(var n=-1,o=e.length,u=o-1,i=t;null!=i&&++n<o;){var c=j(e[n]),a=r;
if(n!=u){var l=i[c],a=E;a===E&&(a=S(l)?l:_(e[n+1])?[]:{})}var s=i,l=c,f=s[l];Q.call(s,l)&&m(f,a)&&(a!==E||l in s)||("__proto__"==l&&ot?ot(s,l,{configurable:true,enumerable:true,value:a,writable:true}):s[l]=a),i=i[c]}}return t},n.unset=function(t,e){var r;if(null==t)r=true;else{var n=t,o=r=h(e,n);if(!(2>o.length)){var u=0,i=-1,c=-1,l=o.length;for(0>u&&(u=-u>l?0:l+u),i=i>l?l:i,0>i&&(i+=l),l=u>i?0:i-u>>>0,u>>>=0,i=Array(l);++c<l;)i[c]=o[c+u];n=a(n,i)}r=j(v(r)),r=!(null!=n&&Q.call(n,r))||delete n[r]}return r;
},n.values=function(t){return null==t?[]:r(t,$(t))},n.eq=m,n.get=function(t,e,r){return t=null==t?E:a(t,e),t===E?r:t},n.isArguments=st,n.isArray=ft,n.isArrayLike=A,n.isBuffer=pt,n.isFunction=O,n.isLength=z,n.isObject=S,n.isObjectLike=w,n.isSymbol=x,n.isTypedArray=ht,n.last=v,n.stubFalse=k,n.toString=F,n.VERSION="4.17.1",G&&((G.exports=n)._=n,V._=n)}).call(this);
File diff suppressed because one or more lines are too long
-33
View File
@@ -1,33 +0,0 @@
{
"preferences": {
"tabSize": 4,
"wordWrap": true,
"useSoftTabs": true,
"gotoExclude": []
},
"packages": [
"gh:wymsee/zed-tools/mobile"
],
"modes": {
"javascript": {
"commands": {
"Tools:Check": {
"options": {
"globals": {
"angular": true,
"$": true,
"device": true,
"persistence": true,
"moment": true,
"sos": true,
"LocalFileSystem": true,
"Hammer": true,
"AnimationFrame": true,
"Bloodhound": true
}
}
}
}
}
}
}