Regression: Fix handling of http requests in apps bridge (#24211)

pull/24112/head^2
Douglas Gubert 3 years ago committed by GitHub
parent 775584f181
commit f92db4fa59
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
  1. 31
      app/apps/server/bridges/http.ts

@ -78,16 +78,33 @@ export class AppHttpBridge extends HttpBridge {
url: info.url, url: info.url,
method: info.method, method: info.method,
statusCode: response.status, statusCode: response.status,
data: await response.json(),
headers: Object.fromEntries(response.headers as unknown as any), headers: Object.fromEntries(response.headers as unknown as any),
}; };
if (request.hasOwnProperty('encoding')) { const body = Buffer.from(await response.arrayBuffer());
if (request.encoding === null) {
result.content = Buffer.from(await response.arrayBuffer()).toString(); if (request.encoding === null) {
} else { /**
result.content = await response.text(); * The property `content` is not appropriately typed in the
} * Apps-engine definition, and we can't simply change it there
* as it would be a breaking change. Thus, we're left with this
* type assertion.
*/
result.content = body as any;
} else {
result.content = body.toString(request.encoding);
result.data = ((): any => {
const contentType = (response.headers.get('content-type') || '').split(';')[0];
if (!['application/json', 'text/javascript', 'application/javascript', 'application/x-javascript'].includes(contentType)) {
return null;
}
try {
return JSON.parse(result.content);
} catch {
return null;
}
})();
} }
return result; return result;

Loading…
Cancel
Save