Skip to content

Allow registration of binary ContentTypes #192

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

Closed
billrobertson42 opened this issue Sep 17, 2018 · 1 comment
Closed

Allow registration of binary ContentTypes #192

billrobertson42 opened this issue Sep 17, 2018 · 1 comment

Comments

@billrobertson42
Copy link
Contributor

billrobertson42 commented Sep 17, 2018

  • Framework version: Any
  • Implementations: Jersey / Spring / Spring Boot / Spark (all)

Scenario

I want to register certain content types as binary so that the AwsProxyHttpServletResponseWriter class will not perform the utf-8 validity scan to see if the data that I'm returning is binary.

I create a pull request: #191 as a strawman for how this might be done.

When you're performing your initial configuration/setup, you can ask the LambdaContainerHandler for its instance of ContainerConfig, and then inform the ContainerConfig about which content types are binary in much the same way that you need to configure them in api-gateway, except that the default setup already configures application/octet-stream and image/(gif|png|jpeg).

Here's a snippet of code that shows how to configure additional binary content types, which is based on the spark initialization code.

private static SparkLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;

static {
    try {
        handler = SparkLambdaContainerHandler.getAwsProxyHandler();
        LambdaContainerHandler.getContainerConfig().addBinaryContentTypes("application/protobuf");

        Routes.create();
        Spark.awaitInitialization();
    } catch (ContainerInitializationException e) {
        // if we fail here. We re-throw the exception to force another cold start
        e.printStackTrace();
        throw new RuntimeException("Could not initialize Spark container", e);
    }
}

Later, when the AwsProxyHttpServletResponseWriter is processing the response, it first checks the configuration to see if the provided content type has been configured as binary, and if it is, then it skips the utf-8 check and immediately treats the response as binary. It still performs the utf-8 conformance check if the content is not configured as binary. As before, once it is determined to be binary, the content is base64 encoded and the base64 encoded flag is set to true.

Expected behavior

n/a This is an enhancement request.

Actual behavior

n/a This is an enhancement request.

Steps to reproduce

n/a This is an enhancement request.

Full log output

n/a

@sapessi sapessi added this to the Release 1.2 milestone Oct 19, 2018
@sapessi
Copy link
Contributor

sapessi commented Oct 19, 2018

Closing this issue since #191 it was merged.

@sapessi sapessi closed this as completed Oct 19, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants