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/responseModifiers/index.js b/src/xhrInterceptor/responseModifiers/index.js
index 2d0b7ce..43ffe6c 100644
--- a/src/xhrInterceptor/responseModifiers/index.js
+++ b/src/xhrInterceptor/responseModifiers/index.js
@@ -54,11 +54,11 @@
});
}
- async intercept(request, response) {
+ async intercept(request) {
const matchingModifiers = await this.#getMatchingModifiers(request);
// If we didn't find any matching modifiers, return the response right away.
- if (matchingModifiers.length === 0) return response;
+ if (matchingModifiers.length === 0) return request.xhr.response;
// Otherwise, apply the modifiers sequentially and set the new response.
let json = getResponseJSON({
@@ -70,7 +70,7 @@
for (const modifier of matchingModifiers) {
json = await modifier.interceptor(request, json);
}
- response = convertJSONToResponse(request, json);
+ const response = convertJSONToResponse(request, json);
request.$newResponse = response;
request.$responseModified = true;
}