From dc8f87a97d242e7ef798513937a31f39df84ab7d Mon Sep 17 00:00:00 2001 From: CaerusKaru Date: Tue, 22 Nov 2022 10:47:38 -0600 Subject: [PATCH] Revert: "refactor(apigateway): Enclose getaway response parameters within single quotes" (#23037) Reverts aws/aws-cdk#22637 This is because single quotes are _not_ desirable if you're using [context variables](https://docs.aws.amazon.com/apigateway/latest/developerguide/api-gateway-gatewayResponse-definition.html), which must be provided without quotes. --- packages/@aws-cdk/aws-apigateway/README.md | 5 +++-- .../aws-apigateway/lib/gateway-response.ts | 3 +-- packages/@aws-cdk/aws-apigateway/lib/util.ts | 16 ---------------- .../aws-apigateway/test/gateway-response.test.ts | 6 ++---- 4 files changed, 6 insertions(+), 24 deletions(-) diff --git a/packages/@aws-cdk/aws-apigateway/README.md b/packages/@aws-cdk/aws-apigateway/README.md index 552f515d61488..cfe75be5b0976 100644 --- a/packages/@aws-cdk/aws-apigateway/README.md +++ b/packages/@aws-cdk/aws-apigateway/README.md @@ -1378,8 +1378,9 @@ api.addGatewayResponse('test-response', { type: apigateway.ResponseType.ACCESS_DENIED, statusCode: '500', responseHeaders: { - 'Access-Control-Allow-Origin': 'test.com', - 'test-key': 'test-value', + // Note that values must be enclosed within a pair of single quotes + 'Access-Control-Allow-Origin': "'test.com'", + 'test-key': "'test-value'", }, templates: { 'application/json': '{ "message": $context.error.messageString, "statusCode": "488", "type": "$context.error.responseType" }' diff --git a/packages/@aws-cdk/aws-apigateway/lib/gateway-response.ts b/packages/@aws-cdk/aws-apigateway/lib/gateway-response.ts index 137b2c66395b4..0ab490a893051 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/gateway-response.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/gateway-response.ts @@ -2,7 +2,6 @@ import { IResource, Resource } from '@aws-cdk/core'; import { Construct } from 'constructs'; import { CfnGatewayResponse, CfnGatewayResponseProps } from './apigateway.generated'; import { IRestApi } from './restapi'; -import { normalizeResponseParameterValue } from './util'; /** * Represents gateway response resource. @@ -89,7 +88,7 @@ export class GatewayResponse extends Resource implements IGatewayResponse { const responseParameters: { [key: string]: string } = {}; for (const [header, value] of Object.entries(responseHeaders)) { - responseParameters[`gatewayresponse.header.${header}`] = normalizeResponseParameterValue(value) ; + responseParameters[`gatewayresponse.header.${header}`] = value; } return responseParameters; } diff --git a/packages/@aws-cdk/aws-apigateway/lib/util.ts b/packages/@aws-cdk/aws-apigateway/lib/util.ts index 29513553d3cf8..e5df3afa246af 100644 --- a/packages/@aws-cdk/aws-apigateway/lib/util.ts +++ b/packages/@aws-cdk/aws-apigateway/lib/util.ts @@ -11,22 +11,6 @@ export function validateHttpMethod(method: string, messagePrefix: string = '') { } } -/** - * Response header values need to be enclosed in single quotes. - */ -export function normalizeResponseParameterValue(value: string) { - if (!value) { - return value; - } - - // check if the value is already enclosed in single quotes - if (value.startsWith("'") && value.endsWith("'")) { - return value; - } - - return `'${value}'`; -} - export function parseMethodOptionsPath(originalPath: string): { resourcePath: string, httpMethod: string } { if (!originalPath.startsWith('/')) { throw new Error(`Method options path must start with '/': ${originalPath}`); diff --git a/packages/@aws-cdk/aws-apigateway/test/gateway-response.test.ts b/packages/@aws-cdk/aws-apigateway/test/gateway-response.test.ts index 438d824d2e9d5..80093aba04de1 100644 --- a/packages/@aws-cdk/aws-apigateway/test/gateway-response.test.ts +++ b/packages/@aws-cdk/aws-apigateway/test/gateway-response.test.ts @@ -45,7 +45,6 @@ describe('gateway response', () => { responseHeaders: { 'Access-Control-Allow-Origin': 'test.com', 'test-key': 'test-value', - 'another-test': "'test-value-enclosed-within-single-quotes'", }, }); @@ -55,9 +54,8 @@ describe('gateway response', () => { RestApiId: stack.resolve(api.restApiId), StatusCode: '500', ResponseParameters: { - 'gatewayresponse.header.Access-Control-Allow-Origin': "'test.com'", - 'gatewayresponse.header.test-key': "'test-value'", - 'gatewayresponse.header.another-test': "'test-value-enclosed-within-single-quotes'", + 'gatewayresponse.header.Access-Control-Allow-Origin': 'test.com', + 'gatewayresponse.header.test-key': 'test-value', }, ResponseTemplates: Match.absent(), });