Chunked responses

Hey everyone,
I would like to know when Kong return a chunked response, I didn’t understand yet why in some responses I get ‘Content-Length’ and in some responses, i get ‘transfer-encoding →chunked’ (not together).
Can someone please explain me the logic?



If Kong transforms the response body before streaming it back to the client, it must discard the upstream response’s Content-Length header, and use chunk encoding instead. That is because of NGINX internals. Once Kong receives and processed the response body, the response headers have already been sent back to the client, and it would be impossible to update the Content-Length header.

Your question is very vague and does not provide a concrete example in which Kong is susceptible to do so (or a list plugins you are using), and as such, I cannot point you to which plugin exactly is triggering this behavior. Nonetheless, the answer would’ve the same.

We build two plugins -

  1. Error-mapper - that change the response body if responseCode is not 200
  2. Response changer - that if needed change the response.

Both of them doing in header_filter
content-length = nil

Error mapper return ‘transfer-encoding →chunked’ and Response Changer return content length (even so he change the response + remove the content length)
Any idea why? where or how I can investigate it?


1 Like

Any idea why? where or how I can investigate it?

Not without seeing the code, configuration, and reproducible examples. You should probably investigate this on your side…

1 Like

After trying to investigate - I can determine that the chunk responses only return in errors (even with all plugins disabled)

You know why? I tried find it in the kong without any success…