I have a database query tool that returns data with Transfer-encoding: chunked. I'd like to use existing varnish infrastructure to cache responses from this tool, but varnish refuses to cache chunked documents. Between varnish and the tool itself, there's nginx proxy but I could not find any way to make it un-chunk the responses. Is there a solution for nginx or any other likewise proxy, that basically would do the following:
- Take the response from the backend, and if it is chunked, buffer it up to preset size
- If the response ends before the limit is reached, repackage it as a single object without chunking and send it out with proper Content-Length
- If the response does not end, send the accumulated data out (with original chunks or as one big chunk) and continue streaming it out from that point forward.