Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Revert: "refactor(apigateway): Enclose getaway response parameters within single quotes" #23037

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions packages/@aws-cdk/aws-apigateway/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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" }'
Expand Down
3 changes: 1 addition & 2 deletions packages/@aws-cdk/aws-apigateway/lib/gateway-response.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down Expand Up @@ -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;
}
Expand Down
16 changes: 0 additions & 16 deletions packages/@aws-cdk/aws-apigateway/lib/util.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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}`);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'",
},
});

Expand All @@ -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(),
});
Expand Down