Added filter for new header and doing atob on the response (#5974)

* Added filter for new header and doing atob on the response

* Added check for status code 200

* Added const vars, added condition of 200 and action type API

* Added comments, NPE check for headers
This commit is contained in:
Ayush Pahwa 2021-07-19 20:13:37 +05:30 committed by GitHub
parent 1dfc624a13
commit cab6c12471
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 26 additions and 0 deletions

View File

@ -110,6 +110,7 @@ export const urlGroupsRegexExp = /^(https?:\/{2}\S+?)(\/[\s\S]*?)(\?(?![^{]*})[\
export const EXECUTION_PARAM_KEY = "executionParams";
export const EXECUTION_PARAM_REFERENCE_REGEX = /this.params/g;
export const RESP_HEADER_DATATYPE = "X-APPSMITH-DATATYPE";
export const API_REQUEST_HEADERS: APIHeaders = {
"Content-Type": "application/json",
};

View File

@ -10,6 +10,7 @@ import {
ExecuteActionPayload,
ExecuteActionPayloadEvent,
PageAction,
RESP_HEADER_DATATYPE,
} from "constants/AppsmithActionConstants/ActionConstants";
import * as log from "loglevel";
import {
@ -119,6 +120,10 @@ import LOG_TYPE from "entities/AppsmithConsole/logtype";
import { matchPath } from "react-router";
import { setDataUrl } from "./PageSagas";
enum ActionResponseDataTypes {
BINARY = "BINARY",
}
export enum NavigationTargetType {
SAME_WINDOW = "SAME_WINDOW",
NEW_WINDOW = "NEW_WINDOW",
@ -863,6 +868,26 @@ function* runActionSaga(
eventName = "RUN_SAAS_API";
}
if (
actionObject.pluginType === PluginType.API &&
payload.statusCode === "200 OK" &&
payload.hasOwnProperty("headers")
) {
const respHeaders = payload.headers;
if (
respHeaders.hasOwnProperty(RESP_HEADER_DATATYPE) &&
respHeaders[RESP_HEADER_DATATYPE].length > 0 &&
respHeaders[RESP_HEADER_DATATYPE][0] ===
ActionResponseDataTypes.BINARY &&
getType(payload.body) === Types.STRING
) {
// Decoding from base64 to handle the binary files because direct
// conversion of binary files to string causes corruption in the final output
// this is to only handle the download of binary files
payload.body = atob(payload.body as string);
}
}
AnalyticsUtil.logEvent(eventName, {
actionId,
actionName: actionObject.name,