Alfred Sawaya
March 26, 2021 07:58PM
Actually, I will need to modify the http status code depending on the
output body contents, so it is not just a question of  content-length,
it is more general than that : I need to have the full backend response
(headers + body) in order to produce the full client response.


It does not seem possible as I understand that the read upstream - write
downstream loop is hardcoded into nginx, and a module does not have any
chance to change that, isn't it ?


ngx_http_upstream_send_request ->

    ngx_http_upstream_process_header ->

        ngx_http_upstream_send_response ->

            ngx_http_send_header and then loop read upstream / write
downstream.



Thank again.

On 26/03/2021 21:05, Alfred Sawaya wrote:
> 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.
>>

_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

Send headers in output body filter ?

Alfred Sawaya 248 March 26, 2021 01:06PM

Re: Send headers in output body filter ?

Maxim Dounin 95 March 26, 2021 03:04PM

Re: Send headers in output body filter ?

Alfred Sawaya 116 March 26, 2021 04:06PM

Re: Send headers in output body filter ?

Alfred Sawaya 142 March 26, 2021 07:58PM

Re: Send headers in output body filter ?

Maxim Dounin 145 March 26, 2021 09:50PM

Re: Send headers in output body filter ?

Alfred Sawaya 114 March 26, 2021 10:40PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 178
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready