Open amperioromano opened 3 months ago
This is the very exact bug as reported in https://github.com/dherault/serverless-offline/issues/1107, which was closed as resolved, but it doesn't look like it is.
A very simple configutation setting in the request that it converts the payload to base64 (contentHandling: CONVERT_TO_TEXT) is not converting the body to base64, eo event.payload is not the expected base64-encoded data.
contentHandling: CONVERT_TO_TEXT
event.payload
Current Behavior
Sample Code
service: my-service plugins: - serverless-offline provider: runtime: nodejs18.x stage: dev functions: hello: events: - http: method: post path: hello request: contentHandling: CONVERT_TO_TEXT handler: handler.hello
"use strict" const { stringify } = JSON exports.hello = async function hello(event) { // event.payload should be encoded as base64 return { body: stringify({ foo: "bar" }), statusCode: 200, } }
Expected behavior/code
event.payload should be encoded as base64 when contentHandling is set to CONVERT_TO_TEXT
Environment
serverless
serverless-offline
node.js
OS
Possible Solution
I think the error is in the HttpServer https://github.com/dherault/serverless-offline/blob/c85a19272c59ad9e7cf1aea74e3442c7607b533a/src/events/alb/HttpServer.js#L176 where it always encodes the payload like this
// Payload processing const encoding = detectEncoding(request) request.payload = request.payload && request.payload.toString(encoding)
detectEncoding only returns either utf8 or binary, but it should be base64 for request contentHandling set to CONVERT_TO_TEXT
utf8
binary
base64
Bug Report
This is the very exact bug as reported in https://github.com/dherault/serverless-offline/issues/1107, which was closed as resolved, but it doesn't look like it is.
A very simple configutation setting in the request that it converts the payload to base64 (
contentHandling: CONVERT_TO_TEXT
) is not converting the body to base64, eoevent.payload
is not the expected base64-encoded data.Current Behavior
Sample Code
Expected behavior/code
event.payload should be encoded as base64 when contentHandling is set to CONVERT_TO_TEXT
Environment
serverless
version: v3.38.0serverless-offline
version: v13.3.3node.js
version: v18.3.0OS
: Ubuntu 20.04Possible Solution
I think the error is in the HttpServer https://github.com/dherault/serverless-offline/blob/c85a19272c59ad9e7cf1aea74e3442c7607b533a/src/events/alb/HttpServer.js#L176 where it always encodes the payload like this
detectEncoding only returns either
utf8
orbinary
, but it should bebase64
for request contentHandling set to CONVERT_TO_TEXT