Flatten threads: fix for application/json+protobuf responses
When a new message is created in a thread, the thread itself is
reloaded, but via an application/json+protobuf request (array-like data)
instead of a regular text/plain request (object-like data). Since the
code didn't work well for these types of requests, the thread didn't
fully load.
This CL fixes this issue by correctly handling application/json+protobuf
responses in the response modifiers.
An issue with the read-only interceptors has also been fixed, and tests
have been added to ensure that the array-like to object-like and
viceversa transformation functions work properly.
Bug: twpowertools:153
Change-Id: If6cd5adc67d676bf36986f325e791124fa71da51
diff --git a/src/xhrInterceptor/XHRProxy.js b/src/xhrInterceptor/XHRProxy.js
index 6254fbf..288142a 100644
--- a/src/xhrInterceptor/XHRProxy.js
+++ b/src/xhrInterceptor/XHRProxy.js
@@ -42,7 +42,7 @@
this.xhr.addEventListener(eventName, function() {
let p;
if (eventName === 'load') {
- p = classThis.responseModifier.intercept(proxyThis, this.response).then(() => {
+ p = classThis.responseModifier.intercept(proxyThis).then(() => {
proxyThis.$responseIntercepted = true;
});
} else {
@@ -82,7 +82,12 @@
utils.matchInterceptors('response', this.$TWPTRequestURL);
if (interceptors.length > 0) {
this.xhr.addEventListener('load', function() {
- var body = utils.getResponseJSON(proxyThis);
+ var body = utils.getResponseJSON({
+ responseType: proxyThis.xhr.responseType,
+ response: proxyThis.xhr.response,
+ $TWPTRequestURL: proxyThis.$TWPTRequestURL,
+ $isArrayProto: proxyThis.$isArrayProto,
+ });
if (body !== undefined)
interceptors.forEach(i => {
utils.triggerEvent(i.eventName, body, proxyThis.$TWPTID);