diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts index 4fe0fe6bda795..8ae395f2b286e 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener-rule.ts @@ -391,7 +391,7 @@ export class ApplicationListenerRule extends Construct { * @internal * @deprecated */ -export function validateFixedResponse(fixedResponse: FixedResponse) { +function validateFixedResponse(fixedResponse: FixedResponse) { if (fixedResponse.statusCode && !/^(2|4|5)\d\d$/.test(fixedResponse.statusCode)) { throw new Error('`statusCode` must be 2XX, 4XX or 5XX.'); } @@ -406,7 +406,7 @@ export function validateFixedResponse(fixedResponse: FixedResponse) { * @internal * @deprecated */ -export function validateRedirectResponse(redirectResponse: RedirectResponse) { +function validateRedirectResponse(redirectResponse: RedirectResponse) { if (redirectResponse.protocol && !/^(HTTPS?|#\{protocol\})$/i.test(redirectResponse.protocol)) { throw new Error('`protocol` must be HTTP, HTTPS, or #{protocol}.'); } diff --git a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener.ts b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener.ts index 69486685c10ef..098128a3da6af 100644 --- a/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener.ts +++ b/packages/@aws-cdk/aws-elasticloadbalancingv2/lib/alb/application-listener.ts @@ -10,7 +10,7 @@ import { IListenerCertificate, ListenerCertificate } from '../shared/listener-ce import { determineProtocolAndPort } from '../shared/util'; import { ListenerAction } from './application-listener-action'; import { ApplicationListenerCertificate } from './application-listener-certificate'; -import { ApplicationListenerRule, FixedResponse, RedirectResponse, validateFixedResponse, validateRedirectResponse } from './application-listener-rule'; +import { ApplicationListenerRule, FixedResponse, RedirectResponse } from './application-listener-rule'; import { IApplicationLoadBalancer } from './application-load-balancer'; import { ApplicationTargetGroup, IApplicationLoadBalancerTarget, IApplicationTargetGroup } from './application-target-group'; import { ListenerCondition } from './conditions'; @@ -377,7 +377,18 @@ export class ApplicationListener extends BaseListener implements IApplicationLis messageBody: props.messageBody, }; - validateFixedResponse(fixedResponse); + /** + * NOTE - Copy/pasted from `application-listener-rule.ts#validateFixedResponse`. + * This was previously a deprecated, exported function, which caused issues with jsii's strip-deprecated functionality. + * Inlining the duplication functionality in v2 only (for now). + */ + if (fixedResponse.statusCode && !/^(2|4|5)\d\d$/.test(fixedResponse.statusCode)) { + throw new Error('`statusCode` must be 2XX, 4XX or 5XX.'); + } + + if (fixedResponse.messageBody && fixedResponse.messageBody.length > 1024) { + throw new Error('`messageBody` cannot have more than 1024 characters.'); + } if (props.priority) { new ApplicationListenerRule(this, id + 'Rule', { @@ -410,7 +421,18 @@ export class ApplicationListener extends BaseListener implements IApplicationLis statusCode: props.statusCode, }; - validateRedirectResponse(redirectResponse); + /** + * NOTE - Copy/pasted from `application-listener-rule.ts#validateRedirectResponse`. + * This was previously a deprecated, exported function, which caused issues with jsii's strip-deprecated functionality. + * Inlining the duplication functionality in v2 only (for now). + */ + if (redirectResponse.protocol && !/^(HTTPS?|#\{protocol\})$/i.test(redirectResponse.protocol)) { + throw new Error('`protocol` must be HTTP, HTTPS, or #{protocol}.'); + } + + if (!redirectResponse.statusCode || !/^HTTP_30[12]$/.test(redirectResponse.statusCode)) { + throw new Error('`statusCode` must be HTTP_301 or HTTP_302.'); + } if (props.priority) { new ApplicationListenerRule(this, id + 'Rule', {