# Header filter

**URL:** <https://www.ruby-forum.com/t/header-filter/117715>\
**Category:** NGINX\
**Created:** [October 19, 2007, 5:30pm UTC](https://www.ruby-forum.com/t/header-filter/117715 "2007-10-19T17:30:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Manlio\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@Manlio\_P](https://www.ruby-forum.com/u/Manlio_P)\
**Post date:** [October 19, 2007, 5:30pm UTC](https://www.ruby-forum.com/t/header-filter/117715/1 "2007-10-19T17:30:50Z")

</div>

I’m trying to define a custom header filter in mod\_wsgi, but my filter  
is not called.

Is this supported?

The filter is very simple, and I need it since Ningx does not set the  
r-\>header\_only flag:

static  
ngx\_int\_t ngx\_http\_wsgi\_header\_filter(ngx\_http\_request\_t _r) {  
/_  
\* A custom filter to enable cache validation in mod\_wsgi.  
\*  
\* NOTE: this header filter SHOULD be executed after the  
\* not\_modified header filter.  
\*/

if (r-\>headers\_out.status != NGX\_HTTP\_NOT\_MODIFIED) {  
return ngx\_http\_next\_header\_filter®;  
}

if (r-\>headers\_out.status \< NGX\_HTTP\_MOVED\_PERMANENTLY) {  
/\* 2XX \*/  
r-\>header\_only = 1;

```
 /* XXX check me */
 r->headers_out.content_type.len = 0;
 r->headers_out.content_type.data = NULL;
 r->headers_out.last_modified_time = -1;
 r->headers_out.last_modified = NULL;
 r->headers_out.content_length = NULL;
 r->headers_out.content_length_n = -1;

```

} else if (r-\>headers\_out.status \< NGX\_HTTP\_BAD\_REQUEST) {  
r-\>header\_only = 1;  
}

return ngx\_http\_next\_header\_filter®;  
}

Thanks and regards Manlio P.

---

<div class="post-metadata">

**Author:** ![Manlio\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@Manlio\_P](https://www.ruby-forum.com/u/Manlio_P)\
**Post date:** [October 19, 2007, 5:39pm UTC](https://www.ruby-forum.com/t/header-filter/117715/2 "2007-10-19T17:39:06Z")

</div>

On Fri, Oct 19, 2007 at 05:07:37PM +0200, Manlio P. wrote:

> I’m trying to define a custom header filter in mod\_wsgi, but my filter  
> is not called.
> 
> Is this supported?

## Yes, of course. It’s seems that your module set in filter chain too late

after ngx\_htpt\_header\_filter\_module.

If you use “config” file configuration, you need to write there:  
HTTP\_AUX\_FILTER\_MODULES="$HTTP\_AUX\_FILTER\_MODULES  
ngx\_http\_YOUR\_filter\_module"

---

<div class="post-metadata">

**Author:** ![Manlio\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@Manlio\_P](https://www.ruby-forum.com/u/Manlio_P)\
**Post date:** [October 19, 2007, 6:27pm UTC](https://www.ruby-forum.com/t/header-filter/117715/3 "2007-10-19T18:27:55Z")

</div>

Igor S. ha scritto:

> If you use “config” file configuration, you need to write there:  
> HTTP\_AUX\_FILTER\_MODULES="$HTTP\_AUX\_FILTER\_MODULES ngx\_http\_YOUR\_filter\_module"

The problem is that I defined the header filter _inside_ the wsgi  
module.

Now I have defined the header filter in a separate file, and it works.

Thanks and regards Manlio P.

---

<div class="post-metadata">

**Author:** ![Manlio\_P](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/m/6f9a4e/32.png) [@Manlio\_P](https://www.ruby-forum.com/u/Manlio_P)\
**Post date:** [October 19, 2007, 7:48pm UTC](https://www.ruby-forum.com/t/header-filter/117715/4 "2007-10-19T19:48:07Z")

</div>

On Fri, Oct 19, 2007 at 06:08:55PM +0200, Manlio P. wrote:

> > If you use “config” file configuration, you need to write there:  
> > HTTP\_AUX\_FILTER\_MODULES="$HTTP\_AUX\_FILTER\_MODULES  
> > ngx\_http\_YOUR\_filter\_module"
> 
> The problem is that I defined the header filter _inside_ the wsgi module.
> 
> Now I have defined the header filter in a separate file, and it works.

The filter order is defined in objs/ngx\_modules.c:

```
&ngx_http_write_filter_module,
&ngx_http_header_filter_module,
&ngx_http_chunked_filter_module,
&ngx_http_range_header_filter_module,
&ngx_http_gzip_filter_module,
&ngx_http_postpone_filter_module,
&ngx_http_charset_filter_module,
&ngx_http_ssi_filter_module,
&ngx_http_sub_filter_module,
&ngx_http_addition_filter_module,
&ngx_http_userid_filter_module,
&ngx_http_headers_filter_module,
&ngx_http_copy_filter_module,
&ngx_http_range_body_filter_module,
&ngx_http_not_modified_filter_module,

```

The two filters ngx\_http\_range\_body\_filter\_module and  
ngx\_http\_range\_header\_filter\_module are in one file, but called in  
different places.
