Welcome! Log In Create A New Profile

Advanced

Re: About the phase handlers init

Maxim Dounin
September 03, 2021 03:36PM
Hello!

On Fri, Sep 03, 2021 at 12:08:32PM +0800, Jinhua Luo wrote:

> In the function ngx_http_init_phase_handlers, I found two places hard
> to understand.
>
> a) The n variable is as known as the next phase handler index. In the
> switch case NGX_HTTP_ACCESS_PHASE, it invokes n++, which seems to be
> redundant and wrong, While in switch case NGX_HTTP_POST_ACCESS_PHASE,
> it lacks n++. Think about that if the number of modules registers as
> NGX_HTTP_ACCESS_PHASE is 0, then the next index is 1 more than the
> correct number. Of course, the current codes have at least one
> NGX_HTTP_POST_ACCESS_PHASE module: ngx_http_access_module, but it
> contains the codes to jump to the next phase handler, then the jump
> target is bypass NGX_HTTP_POST_ACCESS_PHASE and to
> NGX_HTTP_PRECONTENT_PHASE?

The NGX_HTTP_POST_ACCESS_PHASE is a special phase which is only
used when there are modules in the NGX_HTTP_ACCESS_PHASE, and only
contains a single phase handler, ngx_http_core_post_access_phase().
The post-access phase does not need to be present at all when there
are no modules in the access phase. Further, when access phase
checker decides to skip the access phase when access is allowed by
a handler, and needs to switch to the next phase - it does not
need to switch to post-access phase, but rather to the phase after
it. Hence n++ in the access phase case (and not in the
post-access phase).

> b) Does the handler runs in reverse order of registration order?
>
> for (j = cmcf->phases[i].handlers.nelts - 1; j >= 0; j--)

Yes. In particular, this ensures that addon modules are called
first, before the built-in modules.

--
Maxim Dounin
http://mdounin.ru/
_______________________________________________
nginx-devel mailing list
nginx-devel@nginx.org
http://mailman.nginx.org/mailman/listinfo/nginx-devel
Subject Author Views Posted

About the phase handlers init

Jinhua Luo 383 September 03, 2021 12:10AM

Re: About the phase handlers init

Maxim Dounin 164 September 03, 2021 03:36PM

Re: About the phase handlers init

Jinhua Luo 104 September 04, 2021 11:50AM

Re: About the phase handlers init

Jinhua Luo 114 September 04, 2021 11:52AM

Re: About the phase handlers init

Maxim Dounin 127 September 04, 2021 02:30PM



Sorry, you do not have permission to post/reply in this forum.

Online Users

Guests: 245
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 421 on December 02, 2018
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready