Skip to content

Commit dc8f87a

Browse files
authored
Revert: "refactor(apigateway): Enclose getaway response parameters within single quotes" (#23037)
Reverts #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.
1 parent 4dcce2c commit dc8f87a

File tree

4 files changed

+6
-24
lines changed

4 files changed

+6
-24
lines changed

Diff for: packages/@aws-cdk/aws-apigateway/README.md

+3-2
Original file line numberDiff line numberDiff line change
@@ -1378,8 +1378,9 @@ api.addGatewayResponse('test-response', {
13781378
type: apigateway.ResponseType.ACCESS_DENIED,
13791379
statusCode: '500',
13801380
responseHeaders: {
1381-
'Access-Control-Allow-Origin': 'test.com',
1382-
'test-key': 'test-value',
1381+
// Note that values must be enclosed within a pair of single quotes
1382+
'Access-Control-Allow-Origin': "'test.com'",
1383+
'test-key': "'test-value'",
13831384
},
13841385
templates: {
13851386
'application/json': '{ "message": $context.error.messageString, "statusCode": "488", "type": "$context.error.responseType" }'

Diff for: packages/@aws-cdk/aws-apigateway/lib/gateway-response.ts

+1-2
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ import { IResource, Resource } from '@aws-cdk/core';
22
import { Construct } from 'constructs';
33
import { CfnGatewayResponse, CfnGatewayResponseProps } from './apigateway.generated';
44
import { IRestApi } from './restapi';
5-
import { normalizeResponseParameterValue } from './util';
65

76
/**
87
* Represents gateway response resource.
@@ -89,7 +88,7 @@ export class GatewayResponse extends Resource implements IGatewayResponse {
8988

9089
const responseParameters: { [key: string]: string } = {};
9190
for (const [header, value] of Object.entries(responseHeaders)) {
92-
responseParameters[`gatewayresponse.header.${header}`] = normalizeResponseParameterValue(value) ;
91+
responseParameters[`gatewayresponse.header.${header}`] = value;
9392
}
9493
return responseParameters;
9594
}

Diff for: packages/@aws-cdk/aws-apigateway/lib/util.ts

-16
Original file line numberDiff line numberDiff line change
@@ -11,22 +11,6 @@ export function validateHttpMethod(method: string, messagePrefix: string = '') {
1111
}
1212
}
1313

14-
/**
15-
* Response header values need to be enclosed in single quotes.
16-
*/
17-
export function normalizeResponseParameterValue(value: string) {
18-
if (!value) {
19-
return value;
20-
}
21-
22-
// check if the value is already enclosed in single quotes
23-
if (value.startsWith("'") && value.endsWith("'")) {
24-
return value;
25-
}
26-
27-
return `'${value}'`;
28-
}
29-
3014
export function parseMethodOptionsPath(originalPath: string): { resourcePath: string, httpMethod: string } {
3115
if (!originalPath.startsWith('/')) {
3216
throw new Error(`Method options path must start with '/': ${originalPath}`);

Diff for: packages/@aws-cdk/aws-apigateway/test/gateway-response.test.ts

+2-4
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ describe('gateway response', () => {
4545
responseHeaders: {
4646
'Access-Control-Allow-Origin': 'test.com',
4747
'test-key': 'test-value',
48-
'another-test': "'test-value-enclosed-within-single-quotes'",
4948
},
5049
});
5150

@@ -55,9 +54,8 @@ describe('gateway response', () => {
5554
RestApiId: stack.resolve(api.restApiId),
5655
StatusCode: '500',
5756
ResponseParameters: {
58-
'gatewayresponse.header.Access-Control-Allow-Origin': "'test.com'",
59-
'gatewayresponse.header.test-key': "'test-value'",
60-
'gatewayresponse.header.another-test': "'test-value-enclosed-within-single-quotes'",
57+
'gatewayresponse.header.Access-Control-Allow-Origin': 'test.com',
58+
'gatewayresponse.header.test-key': 'test-value',
6159
},
6260
ResponseTemplates: Match.absent(),
6361
});

0 commit comments

Comments
 (0)