# Status line processing in filter module

**URL:** <https://www.ruby-forum.com/t/status-line-processing-in-filter-module/117702>\
**Category:** NGINX\
**Created:** [October 19, 2007, 3:09pm UTC](https://www.ruby-forum.com/t/status-line-processing-in-filter-module/117702 "2007-10-19T15:09:57Z")\
**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, 3:09pm UTC](https://www.ruby-forum.com/t/status-line-processing-in-filter-module/117702/1 "2007-10-19T15:09:57Z")

</div>

Hi.

When trying to enable support for Last-Modified validation in mod\_wsgi I  
have found this code in the filter module:

/\* status line \*/

```
 if (r->headers_out.status_line.len) {
     len += r->headers_out.status_line.len;

```

#if (NGX\_SUPPRESS\_WARN)  
status = NGX\_INVALID\_ARRAY\_INDEX;  
#endif

```
 } else {

```

The problem here is that the WSGI application returns a full status line  
(including the Reason-Phrase).

This means that the not\_modified\_filter has no effect, since nginx will  
not set the status\_code to NGX\_HTTP\_NOT\_MODIFIED and r-\>header\_only = 1.

Of course in mod\_wsgi I can just ignore the Reason-Phrase.

One last thing: does Nginx supports the Etag validation?

Thanks 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:34pm UTC](https://www.ruby-forum.com/t/status-line-processing-in-filter-module/117702/2 "2007-10-19T17:34:23Z")

</div>

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

> Of course in mod\_wsgi I can just ignore the Reason-Phrase.  
> nginx passes status line from proxied server, fastcgi server, etc.  
> untouched.  
> So mod\_wsgi should if-modified-since by itself.

> One last thing: does Nginx supports the Etag validation?

No. I do see any advantages of ETag for serving static files.

---

<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, 8:52pm UTC](https://www.ruby-forum.com/t/status-line-processing-in-filter-module/117702/3 "2007-10-19T20:52:32Z")

</div>

Igor S. ha scritto:

> > ```
> > status = NGX_INVALID_ARRAY_INDEX;
> > 
> > ```
> > 
> > not set the status\_code to NGX\_HTTP\_NOT\_MODIFIED and r-\>header\_only = 1.
> > 
> > Of course in mod\_wsgi I can just ignore the Reason-Phrase.
> 
> nginx passes status line from proxied server, fastcgi server, etc. untouched.  
> So mod\_wsgi should if-modified-since by itself.

Its a nuisance, since Nginx already do it.  
The problem is that it does not set r-\>header\_only = 1, and I can’t do  
just:

rc = ngx\_http\_send\_header®;  
if (rc == NGX\_ERROR || rc \> NGX\_OK || r-\>header\_only) {  
ngx\_http\_wsgi\_finalize\_request(r, rc);  
return;

Well, this means that the validation must be done by the WSGI  
application.

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, 10:15pm UTC](https://www.ruby-forum.com/t/status-line-processing-in-filter-module/117702/4 "2007-10-19T22:15:38Z")

</div>

Manlio P. ha scritto:

> […]
> 
> Well, this means that the validation must be done by the WSGI application.

It seems that I have solved the problem by adding this filter:

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.  
\*/  
static ngx\_str\_t NOT\_MODIFIED = ngx\_string(“304 Not Modified”);

if (r-\>headers\_out.status == NGX\_HTTP\_NOT\_MODIFIED) {  
r-\>header\_only = 1;  
r-\>headers\_out.status\_line = NOT\_MODIFIED;  
}

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

After a few tests it seems that this, finally, works well.

Regards Manlio P.
