http_proto icon indicating copy to clipboard operation
http_proto copied to clipboard

serializer should set Content-Length if body fits into internal buffer after serialization

Open ashtum opened this issue 5 months ago • 1 comments

There are at least two scenarios where this is useful:

  • When we want to use a source object and there is no way to determine the length of the body beforehand (such as when serializing a Boost.JSON value), but we know it can fit into the existing buffer.
  • When we use a compression algorithm and know it can fit into the existing buffer, allowing us to use a Content-Length header instead of chunked encoding.

Related option in Apache: https://httpd.apache.org/docs/current/mod/mod_deflate.html

The DeflateBufferSize directive specifies the size in bytes of the fragments that zlib should compress at one time. If the compressed response size is bigger than the one specified by this directive then httpd will switch to chunked encoding (HTTP header Transfer-Encoding set to Chunked), with the side effect of not setting any Content-Length HTTP header. This is particularly important when httpd works behind reverse caching proxies or when httpd is configured with mod_cache and mod_cache_disk because HTTP responses without any Content-Length header might not be cached.

Possibly similar option in Nginx: https://nginx.org/en/docs/http/ngx_http_gzip_module.html#gzip_buffers

ashtum avatar Aug 27 '25 10:08 ashtum

hold off on this please I think we need to think about it more

vinniefalco avatar Aug 30 '25 14:08 vinniefalco