mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-01-31 00:00:03 +08:00
Compare commits
36 Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
66dc8ff2ca | ||
|
|
91b35d561c | ||
|
|
45c0f8937f | ||
|
|
b1c8427986 | ||
|
|
91470725ee | ||
|
|
7cb41e0c1b | ||
|
|
ee8cae88a9 | ||
|
|
aa8105948e | ||
|
|
325a2e6200 | ||
|
|
8ac8b95246 | ||
|
|
5a7f09bc44 | ||
|
|
308c49635b | ||
|
|
d2a5a113c6 | ||
|
|
2c4ce6f8c7 | ||
|
|
613593ba51 | ||
|
|
a20821378b | ||
|
|
5535464db2 | ||
|
|
7ded66d4b8 | ||
|
|
d84a222dda | ||
|
|
14eef1ca66 | ||
|
|
cf5a684d51 | ||
|
|
c153378b4b | ||
|
|
8092e8b025 | ||
|
|
afb4ea6199 | ||
|
|
2c8c8a14a5 | ||
|
|
8267a02c9d | ||
|
|
a1f678a886 | ||
|
|
69cf4d0939 | ||
|
|
d90cefcbaa | ||
|
|
b3118d5ccd | ||
|
|
6b0f23b2d1 | ||
|
|
d0ece22302 | ||
|
|
a6a1bcaab1 | ||
|
|
4afb375971 | ||
|
|
20e5bd0ee9 | ||
|
|
e84d84c358 |
5
.gitignore
vendored
5
.gitignore
vendored
@@ -1,2 +1,5 @@
|
||||
node_modules/**
|
||||
tags
|
||||
.zedstate
|
||||
.zedstate
|
||||
/www/umd-tough-cookie.js
|
||||
/temp
|
||||
|
||||
4
.npmignore
Normal file
4
.npmignore
Normal file
@@ -0,0 +1,4 @@
|
||||
tags
|
||||
.zedstate
|
||||
/scripts
|
||||
/temp
|
||||
6
.travis.yml
Normal file
6
.travis.yml
Normal file
@@ -0,0 +1,6 @@
|
||||
language: node_js
|
||||
node_js:
|
||||
- lts/*
|
||||
notifications:
|
||||
slack:
|
||||
secure: lXE+2AgsxZU5G5dI91LkMAIgo8MAWfdM7DB5UOtn5LpuNln+2FmJo1gOI7tkdmLOqpXTGYnpI2VyQN3H4nOF21YhuouzD1Sh8n2wtQg1iTm353kuQpqiVhSBX8ZJ7Be1e1G8OsnxoYOxbs4Zo9qI40EruwkvqLCBHWM5MRGyd4M7EFWwb9Z29VZN0y1Nt5g/c3bT76kdKmF+JCLur2OeEKxAity7sIKgZekSqeIMwEVLSxXnda6Dbjc/cg0MJ0iDArkD7iu6fz/Fcrrxgm/pUxjcgvqze7Gy5i31mjEfspnrglWV1cshMd48BTDKCJ2AMmxH8O3GPSWE2txjIvGRWUve7iViNylvmQCVz3Eyf99+4EuuVGa+5PSodQ/CqODx/65EwtcN3PE1tNz2puKOK8nrOJcFkcbG8KTHKUlQtHCkjitbykUnj/hvhLK5/oWlQYVOLWWrHwdGUh8FI8aFPVGjRjWbHbhdayjEIqxwr1ns+6mYrP1EFNXbaeZxnLNC59XpJl1ifuezqYAk7YEiU5j4rtC7YKgyQ3ueb7anOHTJoTMyDn8mpZXgwuyhoBaeEYytQVgRyMtL6Y5cP98Jn2kv0+vdne3rkk9/JEBTo32HOjvoij6rsqEvXC0LhUDJSNadOVdHht0jjoN6zBH37HIE5/3zysLlPcAcHAS83ow=
|
||||
49
CHANGELOG.md
49
CHANGELOG.md
@@ -1,5 +1,54 @@
|
||||
# Changelog
|
||||
|
||||
## v.1.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)
|
||||
|
||||
3
LICENSE
3
LICENSE
@@ -1,5 +1,6 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2017 Mobisys GmbH
|
||||
Copyright (c) 2014 Wymsee, Inc
|
||||
|
||||
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
|
||||
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.
|
||||
SOFTWARE.
|
||||
|
||||
40
README.md
40
README.md
@@ -1,5 +1,6 @@
|
||||
Cordova Advanced HTTP
|
||||
=====================
|
||||
[](https://travis-ci.org/silkimen/cordova-plugin-advanced-http)
|
||||
|
||||
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).
|
||||
@@ -66,6 +67,15 @@ You can choose one of these two:
|
||||
|
||||
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.
|
||||
@@ -101,6 +111,11 @@ Whether or not to validate the domain name in the certificate. This defaults to
|
||||
console.log('error :(');
|
||||
});
|
||||
|
||||
### removeCookies
|
||||
Remove all cookies associated with a given URL.
|
||||
|
||||
cordovaHTTP.removeCookies(url);
|
||||
|
||||
### post<a name="post"></a>
|
||||
Execute a POST request. Takes a URL, data, and headers.
|
||||
|
||||
@@ -168,6 +183,9 @@ Execute a PUT request. Takes a URL, data, and headers. See the [post](#post) d
|
||||
### 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
|
||||
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.
|
||||
|
||||
@@ -199,27 +217,9 @@ Downloads a file and saves it to the device. Takes a URL, parameters, headers,
|
||||
|
||||
## 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)
|
||||
- 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
|
||||
|
||||
## Cookies
|
||||
|
||||
- a cookie set by a request isn't sent in subsequent requests
|
||||
|
||||
Take this into account when using this plugin in 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.
|
||||
We made a few modifications to http-request.
|
||||
|
||||
15
package.json
15
package.json
@@ -1,7 +1,12 @@
|
||||
{
|
||||
"name": "cordova-plugin-advanced-http",
|
||||
"version": "1.4.0",
|
||||
"version": "1.5.10",
|
||||
"description": "Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning",
|
||||
"scripts": {
|
||||
"build": "cp node_modules/umd-tough-cookie/lib/umd-tough-cookie.js www/umd-tough-cookie.js",
|
||||
"prepublish": "npm run build",
|
||||
"test": "npm run build && ./scripts/test-installation.sh"
|
||||
},
|
||||
"cordova": {
|
||||
"id": "cordova-plugin-advanced-http",
|
||||
"platforms": [
|
||||
@@ -25,7 +30,7 @@
|
||||
"engines": [
|
||||
{
|
||||
"name": "cordova",
|
||||
"version": ">=3.0.0"
|
||||
"version": ">=4.0.0"
|
||||
}
|
||||
],
|
||||
"author": "Wymsee",
|
||||
@@ -44,5 +49,9 @@
|
||||
"bugs": {
|
||||
"url": "https://github.com/silkimen/cordova-plugin-advanced-http/issues"
|
||||
},
|
||||
"homepage": "https://github.com/silkimen/cordova-plugin-advanced-http#readme"
|
||||
"homepage": "https://github.com/silkimen/cordova-plugin-advanced-http#readme",
|
||||
"devDependencies": {
|
||||
"cordova": "7.0.1",
|
||||
"umd-tough-cookie": "2.3.2"
|
||||
}
|
||||
}
|
||||
|
||||
16
plugin.xml
16
plugin.xml
@@ -2,7 +2,7 @@
|
||||
<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.4.0">
|
||||
version="1.5.10">
|
||||
|
||||
<name>Advanced HTTP plugin</name>
|
||||
|
||||
@@ -11,12 +11,22 @@
|
||||
</description>
|
||||
|
||||
<engines>
|
||||
<engine name="cordova" version=">=3.5.0" />
|
||||
<engine name="cordova" version=">=4.0.0" />
|
||||
</engines>
|
||||
|
||||
<dependency id="cordova-plugin-file" version=">=2.0.0" />
|
||||
|
||||
<js-module src="www/cordovaHttp.js" name="http">
|
||||
<js-module src="www/lodash.js" name="lodash">
|
||||
</js-module>
|
||||
<js-module src="www/umd-tough-cookie.js" name="tough-cookie">
|
||||
</js-module>
|
||||
<js-module src="www/local-storage-store.js" name="local-storage-store">
|
||||
</js-module>
|
||||
<js-module src="www/cookie-handler.js" name="cookie-handler">
|
||||
</js-module>
|
||||
<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" />
|
||||
</js-module>
|
||||
|
||||
|
||||
12
scripts/test-installation.sh
Executable file
12
scripts/test-installation.sh
Executable file
@@ -0,0 +1,12 @@
|
||||
#!/usr/bin/env bash
|
||||
set -e
|
||||
|
||||
ROOT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/..
|
||||
CDV=$ROOT/node_modules/.bin/cordova
|
||||
|
||||
rm -rf $ROOT/temp
|
||||
$CDV create $ROOT/temp
|
||||
cd $ROOT/temp
|
||||
$CDV platforms add android
|
||||
$CDV platforms add ios
|
||||
$CDV plugins add $ROOT
|
||||
@@ -14,6 +14,8 @@ import java.util.Map;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
import java.util.Iterator;
|
||||
|
||||
import android.text.TextUtils;
|
||||
|
||||
import com.github.kevinsawicki.http.HttpRequest;
|
||||
|
||||
abstract class CordovaHttp {
|
||||
@@ -28,21 +30,24 @@ abstract class CordovaHttp {
|
||||
private JSONObject params;
|
||||
private String serializerName;
|
||||
private JSONObject headers;
|
||||
private int timeoutInMilliseconds;
|
||||
private CallbackContext callbackContext;
|
||||
|
||||
public CordovaHttp(String urlString, JSONObject params, JSONObject headers, CallbackContext callbackContext) {
|
||||
public CordovaHttp(String urlString, JSONObject params, JSONObject headers, int timeout, CallbackContext callbackContext) {
|
||||
this.urlString = urlString;
|
||||
this.params = params;
|
||||
this.serializerName = "default";
|
||||
this.headers = headers;
|
||||
this.timeoutInMilliseconds = timeout;
|
||||
this.callbackContext = callbackContext;
|
||||
}
|
||||
|
||||
public CordovaHttp(String urlString, JSONObject params, String serializerName, JSONObject headers, 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;
|
||||
}
|
||||
|
||||
@@ -88,6 +93,10 @@ abstract class CordovaHttp {
|
||||
return this.getStringMapFromJSONObject(this.headers);
|
||||
}
|
||||
|
||||
protected int getRequestTimeout() {
|
||||
return this.timeoutInMilliseconds;
|
||||
}
|
||||
|
||||
protected CallbackContext getCallbackContext() {
|
||||
return this.callbackContext;
|
||||
}
|
||||
@@ -122,15 +131,18 @@ abstract class CordovaHttp {
|
||||
|
||||
protected void addResponseHeaders(HttpRequest request, JSONObject response) throws JSONException {
|
||||
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()) {
|
||||
String key = entry.getKey();
|
||||
List<String> value = entry.getValue();
|
||||
|
||||
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 {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
package com.synconset.cordovahttp;
|
||||
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.net.ssl.SSLHandshakeException;
|
||||
@@ -16,8 +17,8 @@ import com.github.kevinsawicki.http.HttpRequest;
|
||||
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException;
|
||||
|
||||
class CordovaHttpDelete extends CordovaHttp implements Runnable {
|
||||
public CordovaHttpDelete(String urlString, JSONObject data, JSONObject headers, CallbackContext callbackContext) {
|
||||
super(urlString, data, headers, callbackContext);
|
||||
public CordovaHttpDelete(String urlString, JSONObject data, JSONObject headers, CallbackContext callbackContext, int timeout) {
|
||||
super(urlString, data, headers, timeout, callbackContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,9 +26,11 @@ class CordovaHttpDelete extends CordovaHttp implements Runnable {
|
||||
try {
|
||||
HttpRequest request = HttpRequest.delete(this.getUrlString(), this.getParamsMap(), false);
|
||||
|
||||
request.readTimeout(this.getRequestTimeout());
|
||||
this.setupSecurity(request);
|
||||
request.acceptCharset(CHARSET);
|
||||
request.headers(this.getHeadersMap());
|
||||
request.uncompress(true);
|
||||
|
||||
int code = request.code();
|
||||
String body = request.body(CHARSET);
|
||||
@@ -48,6 +51,8 @@ class CordovaHttpDelete extends CordovaHttp implements Runnable {
|
||||
} 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 {
|
||||
@@ -7,6 +7,7 @@ import com.github.kevinsawicki.http.HttpRequest;
|
||||
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException;
|
||||
|
||||
import java.io.File;
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -22,8 +23,8 @@ import org.json.JSONObject;
|
||||
class CordovaHttpDownload extends CordovaHttp implements Runnable {
|
||||
private String filePath;
|
||||
|
||||
public CordovaHttpDownload(String urlString, JSONObject params, JSONObject headers, CallbackContext callbackContext, String filePath) {
|
||||
super(urlString, params, headers, callbackContext);
|
||||
public CordovaHttpDownload(String urlString, JSONObject params, JSONObject headers, CallbackContext callbackContext, String filePath, int timeout) {
|
||||
super(urlString, params, headers, timeout, callbackContext);
|
||||
this.filePath = filePath;
|
||||
}
|
||||
|
||||
@@ -31,9 +32,12 @@ class CordovaHttpDownload extends CordovaHttp implements Runnable {
|
||||
public void run() {
|
||||
try {
|
||||
HttpRequest request = HttpRequest.get(this.getUrlString(), this.getParamsMap(), true);
|
||||
|
||||
request.readTimeout(this.getRequestTimeout());
|
||||
this.setupSecurity(request);
|
||||
request.acceptCharset(CHARSET);
|
||||
request.headers(this.getHeadersMap());
|
||||
request.uncompress(true);
|
||||
int code = request.code();
|
||||
|
||||
JSONObject response = new JSONObject();
|
||||
@@ -57,6 +61,8 @@ class CordovaHttpDownload extends CordovaHttp implements Runnable {
|
||||
} 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 {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
package com.synconset.cordovahttp;
|
||||
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.net.ssl.SSLHandshakeException;
|
||||
@@ -16,8 +17,8 @@ import com.github.kevinsawicki.http.HttpRequest;
|
||||
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException;
|
||||
|
||||
class CordovaHttpGet extends CordovaHttp implements Runnable {
|
||||
public CordovaHttpGet(String urlString, JSONObject params, JSONObject headers, CallbackContext callbackContext) {
|
||||
super(urlString, params, headers, callbackContext);
|
||||
public CordovaHttpGet(String urlString, JSONObject params, JSONObject headers, CallbackContext callbackContext, int timeout) {
|
||||
super(urlString, params, headers, timeout, callbackContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -25,9 +26,11 @@ class CordovaHttpGet extends CordovaHttp implements Runnable {
|
||||
try {
|
||||
HttpRequest request = HttpRequest.get(this.getUrlString(), this.getParamsMap(), false);
|
||||
|
||||
request.readTimeout(this.getRequestTimeout());
|
||||
this.setupSecurity(request);
|
||||
request.acceptCharset(CHARSET);
|
||||
request.headers(this.getHeadersMap());
|
||||
request.uncompress(true);
|
||||
|
||||
int code = request.code();
|
||||
String body = request.body(CHARSET);
|
||||
@@ -48,6 +51,8 @@ class CordovaHttpGet extends CordovaHttp implements Runnable {
|
||||
} 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 {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
package com.synconset.cordovahttp;
|
||||
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import javax.net.ssl.SSLHandshakeException;
|
||||
@@ -15,8 +16,8 @@ import com.github.kevinsawicki.http.HttpRequest;
|
||||
import com.github.kevinsawicki.http.HttpRequest.HttpRequestException;
|
||||
|
||||
class CordovaHttpHead extends CordovaHttp implements Runnable {
|
||||
public CordovaHttpHead(String urlString, JSONObject params, JSONObject headers, CallbackContext callbackContext) {
|
||||
super(urlString, params, headers, callbackContext);
|
||||
public CordovaHttpHead(String urlString, JSONObject params, JSONObject headers, CallbackContext callbackContext, int timeout) {
|
||||
super(urlString, params, headers, timeout, callbackContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -24,9 +25,11 @@ class CordovaHttpHead extends CordovaHttp implements Runnable {
|
||||
try {
|
||||
HttpRequest request = HttpRequest.head(this.getUrlString(), this.getParamsMap(), true);
|
||||
|
||||
request.readTimeout(this.getRequestTimeout());
|
||||
this.setupSecurity(request);
|
||||
request.acceptCharset(CHARSET);
|
||||
request.headers(this.getHeadersMap());
|
||||
request.uncompress(true);
|
||||
|
||||
int code = request.code();
|
||||
JSONObject response = new JSONObject();
|
||||
@@ -47,6 +50,8 @@ class CordovaHttpHead extends CordovaHttp implements Runnable {
|
||||
} 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 {
|
||||
|
||||
@@ -39,14 +39,16 @@ public class CordovaHttpPlugin extends CordovaPlugin {
|
||||
JSONObject params = args.getJSONObject(1);
|
||||
String serializerName = args.getString(2);
|
||||
JSONObject headers = args.getJSONObject(3);
|
||||
CordovaHttpPost post = new CordovaHttpPost(urlString, params, serializerName, headers, callbackContext);
|
||||
int timeoutInMilliseconds = args.getInt(4) * 1000;
|
||||
CordovaHttpPost post = new CordovaHttpPost(urlString, params, serializerName, headers, callbackContext, timeoutInMilliseconds);
|
||||
|
||||
cordova.getThreadPool().execute(post);
|
||||
} else if (action.equals("get")) {
|
||||
String urlString = args.getString(0);
|
||||
JSONObject params = args.getJSONObject(1);
|
||||
JSONObject headers = args.getJSONObject(2);
|
||||
CordovaHttpGet get = new CordovaHttpGet(urlString, params, headers, callbackContext);
|
||||
int timeoutInMilliseconds = args.getInt(3) * 1000;
|
||||
CordovaHttpGet get = new CordovaHttpGet(urlString, params, headers, callbackContext, timeoutInMilliseconds);
|
||||
|
||||
cordova.getThreadPool().execute(get);
|
||||
} else if (action.equals("put")) {
|
||||
@@ -54,21 +56,24 @@ public class CordovaHttpPlugin extends CordovaPlugin {
|
||||
JSONObject params = args.getJSONObject(1);
|
||||
String serializerName = args.getString(2);
|
||||
JSONObject headers = args.getJSONObject(3);
|
||||
CordovaHttpPut put = new CordovaHttpPut(urlString, params, serializerName, headers, callbackContext);
|
||||
int timeoutInMilliseconds = args.getInt(4) * 1000;
|
||||
CordovaHttpPut put = new CordovaHttpPut(urlString, params, serializerName, headers, callbackContext, timeoutInMilliseconds);
|
||||
|
||||
cordova.getThreadPool().execute(put);
|
||||
} else if (action.equals("delete")) {
|
||||
String urlString = args.getString(0);
|
||||
JSONObject params = args.getJSONObject(1);
|
||||
JSONObject headers = args.getJSONObject(2);
|
||||
CordovaHttpDelete delete = new CordovaHttpDelete(urlString, params, headers, callbackContext);
|
||||
int timeoutInMilliseconds = args.getInt(3) * 1000;
|
||||
CordovaHttpDelete delete = new CordovaHttpDelete(urlString, params, headers, callbackContext, timeoutInMilliseconds);
|
||||
|
||||
cordova.getThreadPool().execute(delete);
|
||||
} else if (action.equals("head")) {
|
||||
String urlString = args.getString(0);
|
||||
JSONObject params = args.getJSONObject(1);
|
||||
JSONObject headers = args.getJSONObject(2);
|
||||
CordovaHttpHead head = new CordovaHttpHead(urlString, params, headers, callbackContext);
|
||||
int timeoutInMilliseconds = args.getInt(3) * 1000;
|
||||
CordovaHttpHead head = new CordovaHttpHead(urlString, params, headers, callbackContext, timeoutInMilliseconds);
|
||||
|
||||
cordova.getThreadPool().execute(head);
|
||||
} else if (action.equals("enableSSLPinning")) {
|
||||
@@ -96,7 +101,8 @@ public class CordovaHttpPlugin extends CordovaPlugin {
|
||||
JSONObject headers = args.getJSONObject(2);
|
||||
String filePath = args.getString(3);
|
||||
String name = args.getString(4);
|
||||
CordovaHttpUpload upload = new CordovaHttpUpload(urlString, params, headers, callbackContext, filePath, name);
|
||||
int timeoutInMilliseconds = args.getInt(5) * 1000;
|
||||
CordovaHttpUpload upload = new CordovaHttpUpload(urlString, params, headers, callbackContext, filePath, name, timeoutInMilliseconds);
|
||||
|
||||
cordova.getThreadPool().execute(upload);
|
||||
} else if (action.equals("downloadFile")) {
|
||||
@@ -104,7 +110,8 @@ public class CordovaHttpPlugin extends CordovaPlugin {
|
||||
JSONObject params = args.getJSONObject(1);
|
||||
JSONObject headers = args.getJSONObject(2);
|
||||
String filePath = args.getString(3);
|
||||
CordovaHttpDownload download = new CordovaHttpDownload(urlString, params, headers, callbackContext, filePath);
|
||||
int timeoutInMilliseconds = args.getInt(4) * 1000;
|
||||
CordovaHttpDownload download = new CordovaHttpDownload(urlString, params, headers, callbackContext, filePath, timeoutInMilliseconds);
|
||||
|
||||
cordova.getThreadPool().execute(download);
|
||||
} else {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
package com.synconset.cordovahttp;
|
||||
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
@@ -15,8 +16,8 @@ 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, CallbackContext callbackContext) {
|
||||
super(urlString, params, serializerName, headers, callbackContext);
|
||||
public CordovaHttpPost(String urlString, JSONObject params, String serializerName, JSONObject headers, CallbackContext callbackContext, int timeout) {
|
||||
super(urlString, params, serializerName, headers, timeout, callbackContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -24,9 +25,11 @@ class CordovaHttpPost extends CordovaHttp implements Runnable {
|
||||
try {
|
||||
HttpRequest request = HttpRequest.post(this.getUrlString());
|
||||
|
||||
request.readTimeout(this.getRequestTimeout());
|
||||
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);
|
||||
@@ -51,9 +54,11 @@ class CordovaHttpPost extends CordovaHttp implements Runnable {
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
this.respondWithError("There was an error generating the response");
|
||||
} catch (HttpRequestException e) {
|
||||
} 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 {
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
*/
|
||||
package com.synconset.cordovahttp;
|
||||
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
|
||||
import org.apache.cordova.CallbackContext;
|
||||
@@ -15,8 +16,8 @@ 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, CallbackContext callbackContext) {
|
||||
super(urlString, data, serializerName, headers, callbackContext);
|
||||
public CordovaHttpPut(String urlString, JSONObject data, String serializerName, JSONObject headers, CallbackContext callbackContext, int timeout) {
|
||||
super(urlString, data, serializerName, headers, timeout, callbackContext);
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -24,9 +25,11 @@ class CordovaHttpPut extends CordovaHttp implements Runnable {
|
||||
try {
|
||||
HttpRequest request = HttpRequest.put(this.getUrlString());
|
||||
|
||||
request.readTimeout(this.getRequestTimeout());
|
||||
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);
|
||||
@@ -54,6 +57,8 @@ class CordovaHttpPut extends CordovaHttp implements Runnable {
|
||||
} 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 {
|
||||
@@ -5,6 +5,7 @@ package com.synconset.cordovahttp;
|
||||
|
||||
import java.io.File;
|
||||
|
||||
import java.net.SocketTimeoutException;
|
||||
import java.net.UnknownHostException;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
@@ -29,8 +30,8 @@ class CordovaHttpUpload extends CordovaHttp implements Runnable {
|
||||
private String filePath;
|
||||
private String name;
|
||||
|
||||
public CordovaHttpUpload(String urlString, JSONObject params, JSONObject headers, CallbackContext callbackContext, String filePath, String name) {
|
||||
super(urlString, params, headers, callbackContext);
|
||||
public CordovaHttpUpload(String urlString, JSONObject params, JSONObject headers, CallbackContext callbackContext, String filePath, String name, int timeout) {
|
||||
super(urlString, params, headers, timeout, callbackContext);
|
||||
this.filePath = filePath;
|
||||
this.name = name;
|
||||
}
|
||||
@@ -40,9 +41,11 @@ class CordovaHttpUpload extends CordovaHttp implements Runnable {
|
||||
try {
|
||||
HttpRequest request = HttpRequest.post(this.getUrlString());
|
||||
|
||||
request.readTimeout(this.getRequestTimeout());
|
||||
this.setupSecurity(request);
|
||||
request.acceptCharset(CHARSET);
|
||||
request.headers(this.getHeadersMap());
|
||||
request.uncompress(true);
|
||||
|
||||
URI uri = new URI(filePath);
|
||||
|
||||
@@ -96,6 +99,8 @@ class CordovaHttpUpload extends CordovaHttp implements Runnable {
|
||||
} 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 {
|
||||
|
||||
@@ -6,11 +6,14 @@
|
||||
@interface CordovaHttpPlugin()
|
||||
|
||||
- (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;
|
||||
|
||||
@end
|
||||
|
||||
|
||||
@implementation CordovaHttpPlugin {
|
||||
AFSecurityPolicy *securityPolicy;
|
||||
}
|
||||
@@ -20,11 +23,11 @@
|
||||
}
|
||||
|
||||
- (void)setRequestSerializer:(NSString*)serializerName forManager:(AFHTTPSessionManager*)manager {
|
||||
if ([serializerName isEqualToString:@"json"]) {
|
||||
manager.requestSerializer = [AFJSONRequestSerializer serializer];
|
||||
} else {
|
||||
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
|
||||
}
|
||||
if ([serializerName isEqualToString:@"json"]) {
|
||||
manager.requestSerializer = [AFJSONRequestSerializer serializer];
|
||||
} else {
|
||||
manager.requestSerializer = [AFHTTPRequestSerializer serializer];
|
||||
}
|
||||
}
|
||||
|
||||
- (void)setRequestHeaders:(NSDictionary*)headers forManager:(AFHTTPSessionManager*)manager {
|
||||
@@ -33,12 +36,61 @@
|
||||
}];
|
||||
}
|
||||
|
||||
- (void)setResults:(NSMutableDictionary*)dictionary withTask:(NSURLSessionTask*)task {
|
||||
if (task.response != nil) {
|
||||
NSHTTPURLResponse *response = (NSHTTPURLResponse *)task.response;
|
||||
- (void)handleSuccess:(NSMutableDictionary*)dictionary withResponse:(NSHTTPURLResponse*)response andData:(id)data {
|
||||
if (response != nil) {
|
||||
[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 {
|
||||
@@ -76,26 +128,29 @@
|
||||
- (void)post:(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];
|
||||
|
||||
CordovaHttpPlugin* __weak weakSelf = self;
|
||||
manager.responseSerializer = [TextResponseSerializer serializer];
|
||||
[manager POST:url parameters:parameters progress:nil success:^(NSURLSessionTask *task, id responseObject) {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
[self setResults: dictionary withTask: task];
|
||||
[dictionary setObject:responseObject forKey:@"data"];
|
||||
[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 setResults: dictionary withTask: task];
|
||||
NSString* errResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding];
|
||||
[dictionary setObject:errResponse forKey:@"error"];
|
||||
[self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
|
||||
|
||||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
|
||||
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}];
|
||||
@@ -104,26 +159,30 @@
|
||||
- (void)get:(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];
|
||||
|
||||
CordovaHttpPlugin* __weak weakSelf = self;
|
||||
|
||||
manager.responseSerializer = [TextResponseSerializer serializer];
|
||||
[manager GET:url parameters:parameters progress:nil success:^(NSURLSessionTask *task, id responseObject) {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
[self setResults: dictionary withTask: task];
|
||||
[dictionary setObject:responseObject forKey:@"data"];
|
||||
[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 setResults: dictionary withTask: task];
|
||||
NSString* errResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding];
|
||||
[dictionary setObject:errResponse forKey:@"error"];
|
||||
[self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
|
||||
|
||||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
|
||||
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}];
|
||||
@@ -132,26 +191,29 @@
|
||||
- (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];
|
||||
|
||||
CordovaHttpPlugin* __weak weakSelf = self;
|
||||
manager.responseSerializer = [TextResponseSerializer serializer];
|
||||
[manager PUT:url parameters:parameters success:^(NSURLSessionTask *task, id responseObject) {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
[self setResults: dictionary withTask: task];
|
||||
[dictionary setObject:responseObject forKey:@"data"];
|
||||
[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 setResults: dictionary withTask: task];
|
||||
NSString* errResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding];
|
||||
[dictionary setObject:errResponse forKey:@"error"];
|
||||
[self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
|
||||
|
||||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
|
||||
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}];
|
||||
@@ -160,26 +222,29 @@
|
||||
- (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];
|
||||
|
||||
CordovaHttpPlugin* __weak weakSelf = self;
|
||||
|
||||
manager.responseSerializer = [TextResponseSerializer serializer];
|
||||
[manager DELETE:url parameters:parameters success:^(NSURLSessionTask *task, id responseObject) {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
[self setResults: dictionary withTask: task];
|
||||
[dictionary setObject:responseObject forKey:@"data"];
|
||||
[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 setResults: dictionary withTask: task];
|
||||
NSString* errResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding];
|
||||
[dictionary setObject:errResponse forKey:@"error"];
|
||||
[self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
|
||||
|
||||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
|
||||
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}];
|
||||
@@ -191,22 +256,25 @@
|
||||
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 setRequestHeaders: headers forManager: manager];
|
||||
[self setTimeout:timeoutInSeconds forManager:manager];
|
||||
|
||||
CordovaHttpPlugin* __weak weakSelf = self;
|
||||
|
||||
manager.responseSerializer = [AFHTTPResponseSerializer serializer];
|
||||
[manager HEAD:url parameters:parameters success:^(NSURLSessionTask *task) {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
[self setResults: dictionary withTask: task];
|
||||
// no 'body' for HEAD request, omitting 'data'
|
||||
[self handleSuccess:dictionary withResponse:(NSHTTPURLResponse*)task.response andData:nil];
|
||||
|
||||
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 setResults: dictionary withTask: task];
|
||||
NSString* errResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding];
|
||||
[dictionary setObject:errResponse forKey:@"error"];
|
||||
[self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
|
||||
|
||||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
|
||||
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}];
|
||||
@@ -215,15 +283,18 @@
|
||||
- (void)uploadFile:(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];
|
||||
NSString *filePath = [command.arguments objectAtIndex: 3];
|
||||
NSString *name = [command.arguments objectAtIndex: 4];
|
||||
NSTimeInterval timeoutInSeconds = [[command.arguments objectAtIndex:5] doubleValue];
|
||||
|
||||
NSURL *fileURL = [NSURL URLWithString: filePath];
|
||||
|
||||
[self setRequestHeaders: headers forManager: manager];
|
||||
[self setTimeout:timeoutInSeconds forManager:manager];
|
||||
|
||||
CordovaHttpPlugin* __weak weakSelf = self;
|
||||
manager.responseSerializer = [TextResponseSerializer serializer];
|
||||
@@ -240,14 +311,14 @@
|
||||
}
|
||||
} progress:nil success:^(NSURLSessionTask *task, id responseObject) {
|
||||
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];
|
||||
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
} failure:^(NSURLSessionTask *task, NSError *error) {
|
||||
NSMutableDictionary *dictionary = [NSMutableDictionary dictionary];
|
||||
[self setResults: dictionary withTask: task];
|
||||
NSString* errResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding];
|
||||
[dictionary setObject:errResponse forKey:@"error"];
|
||||
[self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
|
||||
|
||||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
|
||||
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}];
|
||||
@@ -257,12 +328,15 @@
|
||||
- (void)downloadFile:(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];
|
||||
NSString *filePath = [command.arguments objectAtIndex: 3];
|
||||
NSTimeInterval timeoutInSeconds = [[command.arguments objectAtIndex:4] doubleValue];
|
||||
|
||||
[self setRequestHeaders: headers forManager: manager];
|
||||
[self setTimeout:timeoutInSeconds forManager:manager];
|
||||
|
||||
if ([filePath hasPrefix:@"file://"]) {
|
||||
filePath = [filePath substringFromIndex:7];
|
||||
@@ -292,7 +366,7 @@
|
||||
*
|
||||
* Modified by Andrew Stephan for Sync OnSet
|
||||
*
|
||||
*/
|
||||
*/
|
||||
// Download response is okay; begin streaming output to file
|
||||
NSString* parentPath = [filePath stringByDeletingLastPathComponent];
|
||||
|
||||
@@ -322,15 +396,15 @@
|
||||
|
||||
id filePlugin = [self.commandDelegate getCommandInstance:@"File"];
|
||||
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"];
|
||||
|
||||
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 setResults: dictionary withTask: task];
|
||||
NSString* errResponse = [[NSString alloc] initWithData:(NSData *)error.userInfo[AFNetworkingOperationFailingURLResponseDataErrorKey] encoding:NSUTF8StringEncoding];
|
||||
[dictionary setObject:errResponse forKey:@"error"];
|
||||
[self handleError:dictionary withResponse:(NSHTTPURLResponse*)task.response error:error];
|
||||
|
||||
CDVPluginResult *pluginResult = [CDVPluginResult resultWithStatus:CDVCommandStatus_ERROR messageAsDictionary:dictionary];
|
||||
[weakSelf.commandDelegate sendPluginResult:pluginResult callbackId:command.callbackId];
|
||||
}];
|
||||
|
||||
256
www/advanced-http.js
Normal file
256
www/advanced-http.js
Normal file
@@ -0,0 +1,256 @@
|
||||
/*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]);
|
||||
},
|
||||
validateDomainName: function (validate, success, failure) {
|
||||
return exec(success, failure, 'CordovaHttpPlugin', 'validateDomainName', [validate]);
|
||||
},
|
||||
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]);
|
||||
},
|
||||
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;
|
||||
93
www/angular-integration.js
vendored
Normal file
93
www/angular-integration.js
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
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]);
|
||||
},
|
||||
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
www/cookie-handler.js
Normal file
66
www/cookie-handler.js
Normal 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);
|
||||
}
|
||||
}
|
||||
|
||||
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);
|
||||
});
|
||||
}
|
||||
217
www/cordovaHttp.js
vendored
217
www/cordovaHttp.js
vendored
@@ -1,217 +0,0 @@
|
||||
/*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
|
||||
*
|
||||
*/
|
||||
|
||||
/*
|
||||
* An HTTP Plugin for PhoneGap.
|
||||
*/
|
||||
|
||||
var exec = require('cordova/exec');
|
||||
var validSerializers = ['urlencoded', 'json'];
|
||||
|
||||
// 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];
|
||||
}
|
||||
|
||||
var http = {
|
||||
headers: {},
|
||||
dataSerializer: 'urlencoded',
|
||||
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;
|
||||
},
|
||||
setDataSerializer: function (serializer) {
|
||||
this.dataSerializer = checkSerializer(serializer);
|
||||
},
|
||||
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, data, headers, success, failure) {
|
||||
data = data || {};
|
||||
headers = headers || {};
|
||||
headers = mergeHeaders(this.headers, headers);
|
||||
return exec(success, failure, 'CordovaHttpPlugin', 'post', [url, data, this.dataSerializer, headers]);
|
||||
},
|
||||
get: function (url, params, headers, success, failure) {
|
||||
params = params || {};
|
||||
headers = headers || {};
|
||||
headers = mergeHeaders(this.headers, headers);
|
||||
return exec(success, failure, 'CordovaHttpPlugin', 'get', [url, params, headers]);
|
||||
},
|
||||
put: function (url, data, headers, success, failure) {
|
||||
data = data || {};
|
||||
headers = headers || {};
|
||||
headers = mergeHeaders(this.headers, headers);
|
||||
return exec(success, failure, 'CordovaHttpPlugin', 'put', [url, data, this.dataSerializer, headers]);
|
||||
},
|
||||
delete: function (url, params, headers, success, failure) {
|
||||
params = params || {};
|
||||
headers = headers || {};
|
||||
headers = mergeHeaders(this.headers, headers);
|
||||
return exec(success, failure, 'CordovaHttpPlugin', 'delete', [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) {
|
||||
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]);
|
||||
}
|
||||
};
|
||||
|
||||
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);
|
||||
},
|
||||
setDataSerializer: function (serializer) {
|
||||
return http.setParamSerializer(serializer);
|
||||
},
|
||||
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, 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 = http;
|
||||
183
www/local-storage-store.js
Normal file
183
www/local-storage-store.js
Normal 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
www/lodash.js
Normal file
20
www/lodash.js
Normal 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);
|
||||
Reference in New Issue
Block a user