From: Alexander Ebert Date: Mon, 16 May 2022 09:17:50 +0000 (+0200) Subject: HTTP 204 does not carry a `content-type` X-Git-Tag: 5.5.0_Beta_3~20^2^2~2 X-Git-Url: https://git.stricted.de/?a=commitdiff_plain;h=0d9e1a538dae2bc4ccd2465a89b6a4248d0fe267;p=GitHub%2FWoltLab%2FWCF.git HTTP 204 does not carry a `content-type` See https://www.woltlab.com/community/thread/295631-importer-h%C3%A4ngt-bei-reaktionen-100/ --- diff --git a/ts/WoltLabSuite/Core/Ajax/Request.ts b/ts/WoltLabSuite/Core/Ajax/Request.ts index 928010c51b..9b6d8d0420 100644 --- a/ts/WoltLabSuite/Core/Ajax/Request.ts +++ b/ts/WoltLabSuite/Core/Ajax/Request.ts @@ -140,11 +140,16 @@ class AjaxRequest { xhr.onload = () => { if (xhr.readyState === XMLHttpRequest.DONE) { if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) { - if (options.responseType && xhr.getResponseHeader("Content-Type")!.indexOf(options.responseType) !== 0) { - // request succeeded but invalid response type - this._failure(xhr, options); - } else { + if (xhr.status === 204) { + // HTTP 204 does not contain a body, the `content-type` is undefined. this._success(xhr, options); + } else { + if (options.responseType && xhr.getResponseHeader("Content-Type")!.indexOf(options.responseType) !== 0) { + // request succeeded but invalid response type + this._failure(xhr, options); + } else { + this._success(xhr, options); + } } } else { this._failure(xhr, options); @@ -250,7 +255,7 @@ class AjaxRequest { } } - options.success(data!, xhr.responseText, xhr, options.data!); + options.success(data || {}, xhr.responseText, xhr, options.data!); } this._finalize(options); diff --git a/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Request.js b/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Request.js index 37da9d0885..ffdd084dfc 100644 --- a/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Request.js +++ b/wcfsetup/install/files/js/WoltLabSuite/Core/Ajax/Request.js @@ -112,12 +112,18 @@ define(["require", "exports", "tslib", "./Status", "../Core", "../Dom/Change/Lis xhr.onload = () => { if (xhr.readyState === XMLHttpRequest.DONE) { if ((xhr.status >= 200 && xhr.status < 300) || xhr.status === 304) { - if (options.responseType && xhr.getResponseHeader("Content-Type").indexOf(options.responseType) !== 0) { - // request succeeded but invalid response type - this._failure(xhr, options); + if (xhr.status === 204) { + // HTTP 204 does not contain a body, the `content-type` is undefined. + this._success(xhr, options); } else { - this._success(xhr, options); + if (options.responseType && xhr.getResponseHeader("Content-Type").indexOf(options.responseType) !== 0) { + // request succeeded but invalid response type + this._failure(xhr, options); + } + else { + this._success(xhr, options); + } } } else { @@ -209,7 +215,7 @@ define(["require", "exports", "tslib", "./Status", "../Core", "../Dom/Change/Lis void new Promise((resolve_1, reject_1) => { require(["../BackgroundQueue"], resolve_1, reject_1); }).then(tslib_1.__importStar).then((backgroundQueue) => backgroundQueue.invoke()); } } - options.success(data, xhr.responseText, xhr, options.data); + options.success(data || {}, xhr.responseText, xhr, options.data); } this._finalize(options); }