Welcome! Log In Create A New Profile

Advanced

Re: Buffers Chain

Maxim Dounin
May 23, 2014 05:14AM
Hello!

On Thu, May 22, 2014 at 03:21:56PM +0100, Paulo Silva wrote:

> Hi,
> Let me introduce the Elephant in the room. My name is Paulo and I'm
> from Portugal.
> I am starting developing nginx modules and I'm having a great time
> with buffers chain :D
>
> I'm using nginx as a reverse proxy and my goal is to log the full
> response body (HTML) on the server.
>
> I did start with a filter module with a body_filter and my approach is
> as follow:
>
> 1. Inspect given ngx_chain_t *in linked list to understand if nginx
> has the full response (last_buf)
> 2. On each body_filter call I'm updating a linked list which glues
> given ngx_chain_t *in to the previous ones.
> 3. As soon as I detect the last_buf, I iterate my internal linked list
> (and each linked ngx_chain_t lists), dumping buffers content.
>
> Although I'm reaching the last_buf, I'm missing some bytes.

In no particular order:

- Make sure you are allocating your own ngx_chain_t structures.
Trying to modify ngx_chain_t structures got in *in chain is a
common mistake.

- If you are passing buffers to next filters, it's incorrect to
assume that buffer contents will be available later (a buffer
contents will be eventually sent to a client, and then the
buffer can be reused by its owner).

- If you are not passing buffers to next filters, it's incorrect
to assume that you'll get full response (e.g., with
"output_buffers 1 64", you'll get only first 64 bytes of a
response).

- If you didn't set r->filter_need_in_memory, it's incorrect to
assume that buffers will be in memory.

To log a response body, you'll have to copy contents of all
buffers sent though your filter. Just saving links to buffers is
certainly not enough.

--
Maxim Dounin
http://nginx.org/

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

Buffers Chain

Paulo Silva 997 May 22, 2014 10:24AM

Re: Buffers Chain

Maxim Dounin 568 May 23, 2014 05:14AM

Re: Buffers Chain

Paulo Silva 537 May 23, 2014 05:24AM

Re: Buffers Chain

Maxim Dounin 589 May 23, 2014 06:22AM

Re: Buffers Chain

Paulo Silva 499 May 23, 2014 06:58AM

Re: Buffers Chain

Maxim Dounin 536 May 23, 2014 08:00AM

Re: Buffers Chain

Paulo Silva 515 May 23, 2014 09:18AM

Re: Buffers Chain

Maxim Dounin 522 May 23, 2014 09:42AM

Re: Buffers Chain

Paulo Silva 547 May 23, 2014 09:52AM

Re: Buffers Chain

Paulo Silva 481 May 25, 2014 07:24PM

Re: Buffers Chain

splitice 627 May 26, 2014 04:12AM

Re: Buffers Chain

Paulo Silva 516 May 26, 2014 04:20AM

Re: Buffers Chain

splitice 665 May 26, 2014 04:30AM

Re: Buffers Chain

Paulo Silva 523 May 26, 2014 05:18AM

Re: Buffers Chain

splitice 770 May 26, 2014 05:30AM

Re: Buffers Chain

Paulo Silva 570 May 27, 2014 04:16AM

Re: Buffers Chain

Maxim Dounin 659 May 27, 2014 07:10AM



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

Online Users

Guests: 219
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