Skip to content

Commit b3b9730

Browse files
committed
fix: #438 requests not working correctly on browser platform
1 parent b20faa9 commit b3b9730

File tree

4 files changed

+25
-13
lines changed

4 files changed

+25
-13
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Changelog
22

3+
# 3.2.2
4+
5+
- Fixed #438: requests not working correctly on browser platform because request options are not processed correctly
6+
37
## 3.2.1
48

59
- Fixed #425: plugin crashes on Android SDK levels < 24

README.md

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,9 @@ This defaults to `urlencoded`. You can also override the default content type he
129129

130130
### setRequestTimeout
131131
Set how long to wait for a request to respond, in seconds.
132-
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))
133-
For iOS, this will set [timeout interval](https://developer.apple.com/documentation/foundation/nsmutableurlrequest/1414063-timeoutinterval)
132+
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)).
133+
For iOS, this will set [timeout interval](https://developer.apple.com/documentation/foundation/nsmutableurlrequest/1414063-timeoutinterval).
134+
For browser platform, this will set [timeout](https://developer.mozilla.org/fr/docs/Web/API/XMLHttpRequest/timeout).
134135
```js
135136
cordova.plugin.http.setRequestTimeout(5.0);
136137
```

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
{
22
"name": "cordova-plugin-advanced-http",
3-
"version": "3.2.1",
3+
"version": "3.2.2",
44
"description": "Cordova / Phonegap plugin for communicating with HTTP servers using SSL pinning",
55
"scripts": {
66
"updatecert": "node ./scripts/update-e2e-server-cert.js && node ./scripts/update-e2e-client-cert.js",

src/browser/cordova-http-plugin.js

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -151,23 +151,27 @@ function setHeaders(xhr, headers) {
151151
}
152152

153153
function sendRequest(method, withData, opts, success, failure) {
154-
var data, serializer, headers, timeout, followRedirect, responseType, reqId;
154+
var data, serializer, headers, readTimeout, followRedirect, responseType, reqId;
155155
var url = opts[0];
156156

157157
if (withData) {
158158
data = opts[1];
159159
serializer = opts[2];
160160
headers = opts[3];
161-
timeout = opts[4];
162-
followRedirect = opts[5];
163-
responseType = opts[6];
164-
reqId = opts[7];
161+
// connect timeout not applied
162+
// connectTimeout = opts[4];
163+
readTimeout = opts[5];
164+
followRedirect = opts[6];
165+
responseType = opts[7];
166+
reqId = opts[8];
165167
} else {
166168
headers = opts[1];
167-
timeout = opts[2];
168-
followRedirect = opts[3];
169-
responseType = opts[4];
170-
reqId = opts[5];
169+
// connect timeout not applied
170+
// connectTimeout = opts[2];
171+
readTimeout = opts[3];
172+
followRedirect = opts[4];
173+
responseType = opts[5];
174+
reqId = opts[6];
171175
}
172176

173177
var onSuccess = injectRequestIdHandler(reqId, success);
@@ -229,7 +233,10 @@ function sendRequest(method, withData, opts, success, failure) {
229233

230234
// requesting text instead of JSON because it's parsed in the response handler
231235
xhr.responseType = responseType === 'json' ? 'text' : responseType;
232-
xhr.timeout = timeout * 1000;
236+
237+
// we can't set connect timeout and read timeout separately on browser platform
238+
xhr.timeout = readTimeout * 1000;
239+
233240
setHeaders(xhr, headers);
234241

235242
xhr.onerror = function () {

0 commit comments

Comments
 (0)