Skip to content
This repository has been archived by the owner on May 16, 2023. It is now read-only.

AlbTargetGroupResponse automatically base64 encodes data #49

Open
WhyNotHugo opened this issue Nov 9, 2021 · 6 comments
Open

AlbTargetGroupResponse automatically base64 encodes data #49

WhyNotHugo opened this issue Nov 9, 2021 · 6 comments
Labels
good first issue Good for newcomers

Comments

@WhyNotHugo
Copy link

I'm using this to return some image data from a lambda:

    let resp = AlbTargetGroupResponse {
        status_code: 200,
        body: Some(Body::Binary(buf)),
        headers: HeaderMap::new(),
        is_base64_encoded: true,
        multi_value_headers: HeaderMap::new(),
        status_description: Some(String::from("200 OK")),
    };

It appears that when using body: Some(Body::Binary(buf)), this library automatically encodes the payload in base64.

In this case, is_base64_encoded should be set to true. However, it might make sense to drop the is_base64_encoded field entirely, and auto-generate that based on the type of body:

  • If body is Body::Text -> is_base64_encoded = false.
  • If body is Body::Binary -> is_base64_encoded = true.
  • If body is Body::Empty -> irrelevant...?

Given that most of the code around this is auto-generated, I'm not sure if this is even possible.

Are there any fields that are auto-generated based on other's value? Do you think my suggestion makes sense, or is it simpler to just add a note in the docs explaining that binary content is always base64 encoded?

@LegNeato
Copy link
Contributor

Hmmm, I'll have to think about this. I think we can support this case but it will take some refactoring.

@WhyNotHugo
Copy link
Author

WhyNotHugo commented Nov 10, 2021 via email

@LegNeato
Copy link
Contributor

Is the go code correct in this case? Does it have omitempty?

@WhyNotHugo
Copy link
Author

WhyNotHugo commented Nov 12, 2021

It does not. I've sent a patch via aws/aws-lambda-go#408.

@calavera calavera added the good first issue Good for newcomers label Feb 17, 2022
@WhyNotHugo
Copy link
Author

Go code is now correct: aws/aws-lambda-go#408

I think it's a matter of re-generating the auto-generated code?

@calavera
Copy link
Owner

The Alb code is no longer under the generator, so we can make any adjustments we'd like to improve the experience of using that type, like the automatic encoding selection that you mention in the description.

Feel free to make changes in that module: https://github.com/LegNeato/aws-lambda-events/blob/master/aws_lambda_events/src/alb/mod.rs

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

3 participants