You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
If we have a lambda function that has content type application/octet-stream, the eventpayload received in the lambda function is a string that comes from decoding the payload buffer with encoding utf8. That makes is impossible to convert it back to binary.
"use strict"const{ stringify }=JSONexports.hello=asyncfunctionhello(event){// event.payload should be a string decoded with binary encoding when the content-type is application/octet-streamreturn{body: stringify({foo: "bar"}),statusCode: 200,}}
Expected behavior/code
event.payload should be a string decoded with binary encoding when the content-type is application/octet-stream, but it looks it is utf8.
// Detect the toString encoding from the request headers content-type
// enhance if further content types need to be non utf8 encoded.
export function detectEncoding(request) {
const contentType = request.headers["content-type"]
return typeof contentType === "string" &&
contentType.includes("multipart/form-data")
? "binary"
: "utf8"
}
It should consider the application/octet-stream in the same way as multipart/form-data, as it is not possible to convert back the string to the original binary otherwise.
The text was updated successfully, but these errors were encountered:
Bug Report
If we have a lambda function that has content type
application/octet-stream
, the eventpayload received in the lambda function is a string that comes from decoding the payload buffer with encodingutf8
. That makes is impossible to convert it back to binary.Current Behavior
Sample Code
Expected behavior/code
event.payload should be a string decoded with binary encoding when the content-type is application/octet-stream, but it looks it is utf8.
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
serverless-offline/src/events/alb/HttpServer.js
Line 176 in c85a192
detectEncoding implementation is like
serverless-offline/src/utils/index.js
Line 26 in c85a192
It should consider the
application/octet-stream
in the same way asmultipart/form-data
, as it is not possible to convert back the string to the original binary otherwise.The text was updated successfully, but these errors were encountered: