vapor-community / vapor-aws-lambda-runtime

Run your Vapor api server on AWS Lambda using the official Swift Server runtime.
Apache License 2.0
104 stars 10 forks source link

Returning Protobuf binary data seems to truncate in AWS #20

Open skela opened 1 year ago

skela commented 1 year ago

Have managed to get a nice API proof of concept for JSON responses, but having a hard time doing it for protobuf data.

Already wrote the code to have my vapor API return protobuf data with the appropriate contentType of "application/protobuf" based on whether the client sends an Accept header with application/protobuf, all that works when I run my vapor API locally (both running via docker or just swift run).

But trying to make use of that when the service is running in AWS doesn't work.

After a bit of poking around, I've figured out that the aws RestApi declaration in AWS needed a declaration for "binary_media_types".

For example: binary_media_types=["application/protobuf"]

But it still does not work.

As far as I can tell, it might just require a modification to check the contentType for application/protobuf before creating the APIGateway Response, in these files here:

https://github.com/vapor-community/vapor-aws-lambda-runtime/blob/610aaed1cdd7ef434ed23bc7006000948a221527/Sources/VaporAWSLambdaRuntime/APIGateway.swift#L94

https://github.com/vapor-community/vapor-aws-lambda-runtime/blob/610aaed1cdd7ef434ed23bc7006000948a221527/Sources/VaporAWSLambdaRuntime/APIGatewayV2.swift#L106

Just wanted to raise it as a possible feature request, think it would be pretty cool. If its already possible to get this working somehow, then I would greatly appreciate any hints or information that might help.

Thanks for making such an awesome library !