Rejecting response if content-type mismatches in WoltLab/WCF/Ajax/Request
authorAlexander Ebert <ebert@woltlab.com>
Sun, 24 May 2015 16:41:44 +0000 (18:41 +0200)
committerAlexander Ebert <ebert@woltlab.com>
Sun, 24 May 2015 16:41:44 +0000 (18:41 +0200)
wcfsetup/install/files/js/WoltLab/WCF/Ajax/Request.js

index aa5c0b37a0a08e054a8b3c8268c47cc22f2e7243..78039062d4a57ca2f212b73f5c33fd888b51e058 100644 (file)
@@ -22,6 +22,7 @@ define(['Core', 'Language', 'DOM/ChangeListener', 'DOM/Util', 'UI/Dialog', 'Wolt
                        this._options = Core.extend({
                                // request data
                                data: {},
+                               responseType: 'application/json',
                                type: 'POST',
                                url: '',
                                
@@ -87,7 +88,13 @@ define(['Core', 'Language', 'DOM/ChangeListener', 'DOM/Util', 'UI/Dialog', 'Wolt
                        this._xhr.onload = function() {
                                if (this.readyState === XMLHttpRequest.DONE) {
                                        if (this.status >= 200 && this.status < 300 || this.status === 304) {
-                                               self._success(this, options);
+                                               if (options.responseType && options.responseType !== this.getResponseHeader('Content-Type')) {
+                                                       // request succeeded but invalid response type
+                                                       self._failure(this, options);
+                                               }
+                                               else {
+                                                       self._success(this, options);
+                                               }
                                        }
                                        else {
                                                self._failure(this, options);