[Browser] Fixing error propagation in setHeaders

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.
This commit is contained in:
Alexander Grünewald
2021-11-30 17:04:50 +01:00
committed by GitHub
parent 5b8f20e1c4
commit 935e7d6ba3
+10 -1
View File
@@ -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));