Send headers in output body filter ?

Alfred Sawaya alfred at huji.fr
Fri Mar 26 20:05:50 UTC 2021


Thank you for your reply.


Yes, ngx_http_clear_content_length(r) works as the response becomes
chunked, but actually I wonder if there is a possibility to set the
Content-Length correctly in this case ?

Maybe it is not possible? I could do a patch but I think that if it is
not implemented yet, it should be because I have a wrong architecture or
something like that.



On 26/03/2021 20:02, Maxim Dounin wrote:
> Hello!
>
> On Fri, Mar 26, 2021 at 06:05:27PM +0100, Alfred Sawaya wrote:
>
>> I am developping a nginx C module that aims to modify the backend
>> response (handled by the proxy module) in order to redact specified strings.
>>
>> I have a working module, but I am stuck on a case where the module modfy
>> the length of the backend response. As the output header filter is
>> called before the output body filter, the content-length is already sent
>> when the module get the backend response and modifies it.
>>
>> Is there any normal way to workaround this? I would like to avoid
>> writing a complete upstream handler... I wonder if it is a known use case?
> The usual approach is to remove the Content-Length header if you 
> expect that the response length might be changed by your body 
> filter.  You also have to either remove ETag or change it to a 
> weak one, if present.  For examples see SSI filter, sub filter, 
> addition filter, and many others.
>


More information about the nginx-devel mailing list