[dev] http phase handler

Manlio Perillo manlio_perillo at libero.it
Wed Dec 5 21:54:54 MSK 2007


Igor Sysoev ha scritto:
> On Wed, Dec 05, 2007 at 06:32:23PM +0100, Manlio Perillo wrote:
> 
>> I'm interested in how HTTP phases handlers works in nginx.
>>
>> I would like to add support, in mod_wsgi, to NGX_HTTP_PREACCESS_PHASE, 
>> NGX_HTTP_ACCESS_PHASE and NGX_HTTP_CONTENT_PHASE.
>>
>> I'm reading the sources but I'm not sure to understand how a phase 
>> handler terminates.
>>
>> With a request handler, the handler can return NGX_DONE and then call 
>> ngx_http_finalize_request, but what about a phase handler?
> 
> All phase handlers should simpy return value
> NGX_OK/NGX_DECLINED/NGX_HTTP_FORBIDDEN/etc.
> 

Ok.

> In the context phase there may run a single defined content handler (perl,
> proxy_pass, fastcgi_pass, memcached_pass, flv, empty_gif) or stack
> of handlers: index, autoindex, dav, static.
> 
> If a defined handler calls finally ngx_http_finalize_request(NGX_DECLINED),
> then nginx goes to the stack of handlers. Now only perl can do this.
> 

Ok.
This should be possible with Python, too.
But I can't see an useful application for this.

> The preaccess phase is for generic handlers:
> on NGX_OK it goes to a next phase,
> on NGX_DECLINED it goes to a next handler in the same phase,
> on NGX_AGAIN/NGX_DONE it simply return,
> on NGX_ERROR or NGX_HTTP_... it calls ngx_http_finalize_request()
> 
> The access phase is special to handle NGX_OK/NGX_DECLINED depending on
> satisfy_any. However, I'm going to change it, because now:
> 
>      location / {
>          satisfy_any  on;
>          auth_basic ...
>          # no allow/deny rules
>      }
> 
> does not ask username/password.
> 


Is it possible to return NGX_DONE/NGX_AGAIN from the access phase 
handler and then call ngx_http_finalize_request(NGX_HTTP_...) when the 
handler is done (as an example it may setup the events when doing an 
asynchronous query to a database)?



The only module with a phase handler that does "interesting" things is 
the autoindex module, but it uses sub requests (and I have yet to 
understand how they works :)).



Thanks  Manlio Perillo






More information about the nginx mailing list