From 935e7d6ba3546e360edde7b9164ce9383dd9dc97 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexander=20Gr=C3=BCnewald?= <64912706+alexander-gruenewald@users.noreply.github.com> Date: Tue, 30 Nov 2021 17:04:50 +0100 Subject: [PATCH] [Browser] Fixing error propagation in setHeaders MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit If the headers contain certain special characters (€, “, ≠, ∑, †, Ω etc..), calling the setHeaders method will throw an "Value is not a valid ByteString" error which unfortunately is neither propagated to the caller of the http-plugin, nor is the xhr request cancelled in this case. By wrapping the setHeader-call into a try/catch, and fail the xhr request in case of an error, we make sure the caller of the http-plugin will receive a proper error and the xhr request gets canceled. --- src/browser/cordova-http-plugin.js | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/src/browser/cordova-http-plugin.js b/src/browser/cordova-http-plugin.js index bc9d4bc..48ab0d2 100644 --- a/src/browser/cordova-http-plugin.js +++ b/src/browser/cordova-http-plugin.js @@ -237,7 +237,16 @@ function sendRequest(method, withData, opts, success, failure) { // we can't set connect timeout and read timeout separately on browser platform xhr.timeout = readTimeout * 1000; - setHeaders(xhr, headers); + try { + setHeaders(xhr, headers); + } catch(error) { + return onFail({ + status: -8, + error: error, + url: url, + headers: headers + }); + } xhr.onerror = function () { return onFail(createXhrFailureObject(xhr));