Status line processing in filter module

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.

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.

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.

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.