httpencodingkrakend

Krakend added number to request body


When I try to use krakend as API gateway and make POST request, it adds an additional number to data. Example of request:

curl -X POST -H "Content-Type: application/json" -d '{"username":"***","password":"***"}' http://127.0.0.1:8000/api/v1/token

Source of request received by webserver(after krakend):

b'POST /api/v1/token HTTP/1.1\r\nHost: host.docker.internal:8000\r\nUser-Agent: KrakenD Version 2.4.3\r\nTransfer-Encoding: chunked\r\nContent-Type: application/json\r\nX-Forwarded-For: 172.17.0.1\r\nX-Forwarded-Host: 127.0.0.1:8080\r\nAccept-Encoding: gzip\r\n\r\n'
b'23\r\n{"username":"***","password":"***"}\r\n'
b'0\r\n\r\n'

krakend.json config:

{
  "version": 3,
  "debug_endpoint": true,
  "endpoints": [
    {
      "endpoint": "/api/v1/token",
      "method": "POST",
      "backend": [
        {
          "url_pattern": "/api/v1/token",
          "method": "POST",
          "host": [ "http://host.docker.internal:8000" ]
        }
      ]
    }
  ]
}

If I use a direct request to the backend it doesn't contain 23 before the body.

Why do I have this number after the krakend gateway?


Solution

  • Adding this option to endpoint helped me resolve this problem:

    "input_headers": ["Content-Type", "Content-Length"]
    

    Detail information: https://www.krakend.io/docs/endpoints/parameter-forwarding/

    PS My krakend version is v2.4.3(This option called different in previous versions).