fix: #372 [Bug] Android: malformed empty multipart requests

This commit is contained in:
Sefa Ilkimen
2021-07-07 03:16:43 +02:00
parent c081060a9e
commit badf6dcdc2
2 changed files with 12 additions and 4 deletions
@@ -189,8 +189,9 @@ abstract class CordovaHttpBase implements Runnable {
}
// prevent sending malformed empty multipart requests (#372)
if (buffers.length == 0) {
request.contentType(HttpRequest.CONTENT_TYPE_FORM);
if (buffers.length() == 0) {
request.contentType("multipart/form-data; boundary=00content0boundary00");
request.send("\r\n--00content0boundary00--\r\n");
}
}
}
+9 -2
View File
@@ -1121,11 +1121,18 @@ const tests = [
var options = { method: 'post', data: formData };
cordova.plugin.http.sendRequest(url, options, resolve, reject);
},
validationFunc: function (driver, result) {
validationFunc: function (driver, result, targetInfo) {
helpers.checkResult(result, 'resolved');
var parsed = JSON.parse(result.data.data);
parsed.headers['Content-Type'].should.be.equal('application/x-www-form-urlencoded');
if (targetInfo.isAndroid) {
// boundary should be sent correctly on Android
parsed.headers['Content-Type'].should.be.equal('multipart/form-data; boundary=00content0boundary00');
} else {
// falling back to empty url encoded request on iOS
parsed.headers['Content-Type'].should.be.equal('application/x-www-form-urlencoded');
}
}
},
];