gravitee-io / issues

Gravitee.io - API Platform - Issues
65 stars 26 forks source link

[policies] Truncated `request.content` in Callout Http Policy when body contains accents #8109

Closed alambert-idkids closed 2 years ago

alambert-idkids commented 2 years ago

:collision: Describe the bug

Hi Gravitee Team ! I encounetred a probleme with the policy Http Callout.

Via this one, I want to make a call with the original body of the request.

When the body doesn't contains accented characters, everything is ok ! But when the body contains accented characters, the sent body is truncated ✂️

:sunrise_over_mountains: To Reproduce

  1. Create a new API

  2. Add HTTP Callout policy on request flow

  3. Configure the policy:

    • Scope: REQUEST_CONTENT
    • HTTP Method: POST
    • Request body: {#request.content})
  4. Make a POST request to the API with body containing accents

    {
    "name": "name with accents éà"
    }

:rainbow: Expected behaviour

The backend server receives the following body:

{
    "name": "name with accents éà"
}

🌧️ Current behaviour

The backend server receives the following body:

{
    "name": "name with accents éà"

:movie_camera: Useful information

image

Simple node.js server code:

const http = require('http')

const port = process.env.PORT || 3000

const server = http.createServer(async (req, res) => {
    const buffers = [];

    for await (const chunk of req) {
      buffers.push(chunk);
    }

    const data = Buffer.concat(buffers).toString();

    console.log(data);

    res.end();
  });

server.listen(port, () => {
  console.log(`Server running at port ${port}`)
})

:computer: Environment:

🩹 Possible fix

The fix is ​​potentially the same as this

The content length should be miscalculated

image

gaetanmaisse commented 2 years ago

@alambert-idkids 🎉 the fix for this issue has been released in 1.15.1: