# Re: question about addition filter

**URL:** <https://www.ruby-forum.com/t/re-question-about-addition-filter/158869>\
**Category:** NGINX\
**Created:** [January 28, 2009, 10:45pm UTC](https://www.ruby-forum.com/t/re-question-about-addition-filter/158869 "2009-01-28T22:45:05Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mohammad\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@Mohammad\_K](https://www.ruby-forum.com/u/Mohammad_K)\
**Post date:** [January 28, 2009, 10:45pm UTC](https://www.ruby-forum.com/t/re-question-about-addition-filter/158869/1 "2009-01-28T22:45:05Z")

</div>

Igor,

I tried your config, with 0.7.32 and 0.7.31, with/without debug,  
with/without optimization, but I constantly get garbage before and after  
the content of /y/index.html. Maybe it is returning some uninitialized  
memory?

I might be totally wrong, but Evan’s module development tutorial  
mentions something about NGX\_AGAIN and that we should return NGX\_AGAIN  
if ngx\_http\_subrequest returns NGX\_AGAIN. But looking in to your code,  
ngx\_http\_addition\_filter\_module.c, line numbers 154 and 183, you are  
always returning NGX\_ERROR if ngx\_http\_subrequest does not return  
NGX\_OK. Could that be the reason?

Thanks,  
-M

ps, I doubt it matters, but I have CentOS 5.2 64 bit.

* * *

From: Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: removed\_email\_address@domain.invalid  
Sent: Wednesday, January 28, 2009 12:04:35 PM  
Subject: Re: question about addition filter

On Wed, Jan 28, 2009 at 11:21:35AM -0800, Mohammad K. wrote:

> which would supposedly add the content of the [www.yahoo.com](http://www.yahoo.com) and [www.google.com](http://www.google.com) before and after the content of the page at /y/index.html? The addition filter module states that the texts after add\_before\_body and add\_after\_body are URI, but the above config doesn’t seem to be doing it!

This should work, but it’s better to use 0.7.32 for this:

```
     location = /x {
         proxy_pass http://www.yahoo.com/;
     }

     location = /g{
         proxy_pass http://www.google.com/;
     }

     location /y {
         add_before_body /x;
         add_after_body /q;
     }

```

---

<div class="post-metadata">

**Author:** ![Mohammad\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@Mohammad\_K](https://www.ruby-forum.com/u/Mohammad_K)\
**Post date:** [January 28, 2009, 10:49pm UTC](https://www.ruby-forum.com/t/re-question-about-addition-filter/158869/2 "2009-01-28T22:49:47Z")

</div>

On Wed, Jan 28, 2009 at 01:28:50PM -0800, Mohammad K. wrote:

> ps, I doubt it matters, but I have CentOS 5.2 64 bit.  
> This may be gzipped content returned by external sites:

```
      location = /x {
          proxy_pass http://www.yahoo.com/;

```

- 

```
        proxy_set_header Accept-Encoding "";
    }

    location = /g{
        proxy_pass http://www.google.com/;

```

- 

```
        proxy_set_header Accept-Encoding "";
    }
```

---

<div class="post-metadata">

**Author:** ![Mohammad\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@Mohammad\_K](https://www.ruby-forum.com/u/Mohammad_K)\
**Post date:** [January 28, 2009, 11:19pm UTC](https://www.ruby-forum.com/t/re-question-about-addition-filter/158869/3 "2009-01-28T23:19:43Z")

</div>

That was the problem, the content was zipped, everything is working now.

Thanks,  
-M

* * *

From: Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: removed\_email\_address@domain.invalid  
Sent: Wednesday, January 28, 2009 1:39:50 PM  
Subject: Re: question about addition filter

On Wed, Jan 28, 2009 at 01:28:50PM -0800, Mohammad K. wrote:

> ps, I doubt it matters, but I have CentOS 5.2 64 bit.  
> This may be gzipped content returned by external sites:

```
      location = /x {
          proxy_pass http://www.yahoo.com/;

```

- 

```
        proxy_set_header Accept-Encoding "";
    }

    location = /g{
        proxy_pass http://www.google.com/;

```

- 

```
        proxy_set_header Accept-Encoding "";
    }

```

---

<div class="post-metadata">

**Author:** ![Mohammad\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@Mohammad\_K](https://www.ruby-forum.com/u/Mohammad_K)\
**Post date:** [January 28, 2009, 11:44pm UTC](https://www.ruby-forum.com/t/re-question-about-addition-filter/158869/4 "2009-01-28T23:44:57Z")

</div>

What if I wanted to write a module that does something like this: if  
input request is something like [http://localhost/y?a=foo&b=bar](http://localhost/y?a=foo&b=bar), then  
have the before\_body fetch [yahoo.com/foo](http://yahoo.com/foo) and after\_body get the content  
of [google.com/bar](http://google.com/bar) (i.e., the URLs can bo modified on the fly). Is this  
doable, possibly by modifying the content of uri that is passed to  
ngx\_http\_subrequest, or is there another alternative?

Thanks,  
-M

* * *

From: Igor S. [removed\_email\_address@domain.invalid](mailto:removed_email_address@domain.invalid)  
To: removed\_email\_address@domain.invalid  
Sent: Wednesday, January 28, 2009 1:39:50 PM  
Subject: Re: question about addition filter

On Wed, Jan 28, 2009 at 01:28:50PM -0800, Mohammad K. wrote:

> ps, I doubt it matters, but I have CentOS 5.2 64 bit.  
> This may be gzipped content returned by external sites:

```
      location = /x {
          proxy_pass http://www.yahoo.com/;

```

- 

```
        proxy_set_header Accept-Encoding "";
    }

    location = /g{
        proxy_pass http://www.google.com/;

```

- 

```
        proxy_set_header Accept-Encoding "";
    }

```

---

<div class="post-metadata">

**Author:** ![Mohammad\_K](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/8e8cbc/32.png) [@Mohammad\_K](https://www.ruby-forum.com/u/Mohammad_K)\
**Post date:** [January 29, 2009, 9:03am UTC](https://www.ruby-forum.com/t/re-question-about-addition-filter/158869/5 "2009-01-29T09:03:17Z")

</div>

On Wed, Jan 28, 2009 at 02:34:54PM -0800, Mohammad K. wrote:

> What if I wanted to write a module that does something like this: if input request is something like [http://localhost/y?a=foo&b=bar](http://localhost/y?a=foo&b=bar), then have the before\_body fetch [yahoo.com/foo](http://yahoo.com/foo) and after\_body get the content of [google.com/bar](http://google.com/bar) (i.e., the URLs can bo modified on the fly). Is this doable, possibly by modifying the content of uri that is passed to ngx\_http\_subrequest, or is there another alternative?

Currently add\_xxxx\_body does not support variables.  
If it could, then it would be possible:

```
      location /x/ {
          proxy_pass http://www.yahoo.com/;
      }

      location /g/ {
          proxy_pass http://www.google.com/;
      }

      location /y {
          add_before_body /x/$arg_a;
          add_after_body /q/$arg_b;

```
