mirror of
https://github.com/silkimen/cordova-plugin-advanced-http.git
synced 2026-04-24 00:00:03 +08:00
fix: #438 requests not working correctly on browser platform
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
# Changelog
|
||||
|
||||
# 3.2.2
|
||||
|
||||
- Fixed #438: requests not working correctly on browser platform because request options are not processed correctly
|
||||
|
||||
## 3.2.1
|
||||
|
||||
- Fixed #425: plugin crashes on Android SDK levels < 24
|
||||
|
||||
@@ -129,8 +129,9 @@ This defaults to `urlencoded`. You can also override the default content type he
|
||||
|
||||
### setRequestTimeout
|
||||
Set how long to wait for a request to respond, in seconds.
|
||||
For Android, this will set both [connectTimeout](https://developer.android.com/reference/java/net/URLConnection#getConnectTimeout()) and [readTimeout](https://developer.android.com/reference/java/net/URLConnection#setReadTimeout(int))
|
||||
For iOS, this will set [timeout interval](https://developer.apple.com/documentation/foundation/nsmutableurlrequest/1414063-timeoutinterval)
|
||||
For Android, this will set both [connectTimeout](https://developer.android.com/reference/java/net/URLConnection#getConnectTimeout()) and [readTimeout](https://developer.android.com/reference/java/net/URLConnection#setReadTimeout(int)).
|
||||
For iOS, this will set [timeout interval](https://developer.apple.com/documentation/foundation/nsmutableurlrequest/1414063-timeoutinterval).
|
||||
For browser platform, this will set [timeout](https://developer.mozilla.org/fr/docs/Web/API/XMLHttpRequest/timeout).
|
||||
```js
|
||||
cordova.plugin.http.setRequestTimeout(5.0);
|
||||
```
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "cordova-plugin-advanced-http",
|
||||
"version": "3.2.1",
|
||||
"version": "3.2.2",
|
||||
"description": "Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning",
|
||||
"scripts": {
|
||||
"updatecert": "node ./scripts/update-e2e-server-cert.js && node ./scripts/update-e2e-client-cert.js",
|
||||
|
||||
Vendored
+17
-10
@@ -151,23 +151,27 @@ function setHeaders(xhr, headers) {
|
||||
}
|
||||
|
||||
function sendRequest(method, withData, opts, success, failure) {
|
||||
var data, serializer, headers, timeout, followRedirect, responseType, reqId;
|
||||
var data, serializer, headers, readTimeout, followRedirect, responseType, reqId;
|
||||
var url = opts[0];
|
||||
|
||||
if (withData) {
|
||||
data = opts[1];
|
||||
serializer = opts[2];
|
||||
headers = opts[3];
|
||||
timeout = opts[4];
|
||||
followRedirect = opts[5];
|
||||
responseType = opts[6];
|
||||
reqId = opts[7];
|
||||
// connect timeout not applied
|
||||
// connectTimeout = opts[4];
|
||||
readTimeout = opts[5];
|
||||
followRedirect = opts[6];
|
||||
responseType = opts[7];
|
||||
reqId = opts[8];
|
||||
} else {
|
||||
headers = opts[1];
|
||||
timeout = opts[2];
|
||||
followRedirect = opts[3];
|
||||
responseType = opts[4];
|
||||
reqId = opts[5];
|
||||
// connect timeout not applied
|
||||
// connectTimeout = opts[2];
|
||||
readTimeout = opts[3];
|
||||
followRedirect = opts[4];
|
||||
responseType = opts[5];
|
||||
reqId = opts[6];
|
||||
}
|
||||
|
||||
var onSuccess = injectRequestIdHandler(reqId, success);
|
||||
@@ -229,7 +233,10 @@ function sendRequest(method, withData, opts, success, failure) {
|
||||
|
||||
// requesting text instead of JSON because it's parsed in the response handler
|
||||
xhr.responseType = responseType === 'json' ? 'text' : responseType;
|
||||
xhr.timeout = timeout * 1000;
|
||||
|
||||
// we can't set connect timeout and read timeout separately on browser platform
|
||||
xhr.timeout = readTimeout * 1000;
|
||||
|
||||
setHeaders(xhr, headers);
|
||||
|
||||
xhr.onerror = function () {
|
||||
|
||||
Reference in New Issue
Block a user