diff --git a/CHANGELOG.md b/CHANGELOG.md index 3708706..047d2fb 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/README.md b/README.md index ef6f9ae..7b423ba 100644 --- a/README.md +++ b/README.md @@ -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); ``` diff --git a/package.json b/package.json index 1cd69a9..2610b07 100644 --- a/package.json +++ b/package.json @@ -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", diff --git a/src/browser/cordova-http-plugin.js b/src/browser/cordova-http-plugin.js index 5a28525..bc9d4bc 100644 --- a/src/browser/cordova-http-plugin.js +++ b/src/browser/cordova-http-plugin.js @@ -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 () {