Skip to content
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

CONVERT_TO_TEXT parameter does not convert binary data of the request to base64 #1774

Open
amperioromano opened this issue Apr 6, 2024 · 0 comments

Comments

@amperioromano
Copy link

amperioromano commented Apr 6, 2024

Bug Report

This is the very exact bug as reported in #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.

Current Behavior

Sample Code

  • file: serverless.yml
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
  • file: handler.js
"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 version: v3.38.0
  • serverless-offline version: v13.3.3
  • node.js version: v18.3.0
  • OS: Ubuntu 20.04

Possible Solution

I think the error is in the HttpServer

request.payload = request.payload && request.payload.toString(encoding)
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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant