private ObjectNode updateGatewayResponse(
            Context<? extends Trait> context,
            CorsTrait trait,
            Map<CorsHeader, String> sharedHeaders,
            ObjectNode gatewayResponse
    ) {
        ObjectNode responseParameters = gatewayResponse
                .getObjectMember(RESPONSE_PARAMETERS_KEY)
                .orElse(Node.objectNode());

        // Track all CORS headers of the gateway response.
        Map<CorsHeader, String> headers = new TreeMap<>(sharedHeaders);

        // Add the modeled additional headers. These could potentially be added by an
        // apigateway feature, so they need to be present.
        Set<String> exposedHeaders = new TreeSet<>(String.CASE_INSENSITIVE_ORDER);
        exposedHeaders.addAll(trait.getAdditionalExposedHeaders());

        // Find all headers exposed already in the response. These need to be added to the
        // Access-Control-Expose-Headers header if any are found.
        for (String key : responseParameters.getStringMap().keySet()) {
            if (key.startsWith(HEADER_PREFIX)) {
                exposedHeaders.add(key.substring(HEADER_PREFIX.length()));
            }
        }

        if (!exposedHeaders.isEmpty()) {
            headers.put(CorsHeader.EXPOSE_HEADERS, String.join(",", exposedHeaders));
        }

        // Merge the defined response parameters with the derived CORS headers.
        ObjectNode.Builder responseBuilder = responseParameters.toBuilder();
        for (Map.Entry<CorsHeader, String> entry : headers.entrySet()) {
            String key = HEADER_PREFIX + entry.getKey().toString();
            if (!responseParameters.getMember(key).isPresent()) {
                responseBuilder.withMember(key, "'" + entry.getValue() + "'");
            }
        }

        return gatewayResponse.withMember(RESPONSE_PARAMETERS_KEY, responseBuilder.build());
    }
The default gateway response for 4xx and 5xx.

TODO: Does this need to be made protocol-specific?
smithy-aws-apigateway-openapi/src/main/java/software/amazon/smithy/aws/apigateway/openapi/AddCorsToGatewayResponses.java