Openresty defaults to chunked_transfer_encoding on, which means chunked encoding is used. At this time, content-length is useless.
Then our client has a demand for this field, and our business logic is relatively simple, so I turned off chunked. At this time, it becomes a short connection, but the content-length field will not be automatically generated. If I have to manually calculate the returned content length before each return, it will be more laborious, and I am dynamically generating the content.
This problem has nothing to do with whether it is openresty, but when outputting dynamic content, the web server will not know the size of the content you want to output at all. If it is a static resource, the web server will be able to obtain the resource when outputting these static resources. size, you can also specify the content-length response header. Therefore, if dynamic content needs to support the content-length response header, you can only add it yourself.