Welcome! Log In Create A New Profile

Advanced

Re: creating a response from the "access" phase

agentzh
August 09, 2010 10:52PM
On Tue, Jul 27, 2010 at 7:52 PM, Hassan Syed <h.a.syed@gmail.com> wrote:
>
> Question two: Simply returning NGX_HTTP_MOVED_TEMPORARILY from the handler
> with the requesite response headers set should cause the
> "ngx_http_core_access_phase" checker to redirect the connection properly --
> am I right ?
>

Nope :)

See the ngx_http_core_access_phase function in the nginx core for the reason :)

> Question Three: If I were to generate a response body from the
> NGX_HTTP_ACCESS_PHASE should I populate a "ngx_chain_t" and end my handler
> with "return ngx_http_output_filter(r, &out);" as shown in
> "http/modules/ngx_http_static_module.c" ? will this lead to the desired
> behavior, or is this sequence of calls meant only for the
> "NGX_HTTP_CORE_CONTENT_PHASE" ?
>

"return ngx_http_output_filter(r, &out)" is bad for access phase
handlers. The return value of an access phase handler and that of a
content handler have different semantics. See the
ngx_http_core_access_phase function definition in the
ngx_http_core_module.c file of the nginx core. Calling output filters
in the access phase handler itself is fine. I did something similar in
my ngx_srcache module:

http://github.com/agentzh/srcache-nginx-module

> My fourth and final question (which is related to the first) is about
> setting the cache-control headers from theĀ  NGX_HTTP_ACCESS_PHASE. Are there
> any ramifications for directly setting this ?

That's fine. Even though the standard ngx_headers module does that in
an output filter.

My ngx_headers_more module can modify request headers in a rewrite
phase handler, which can serve as a real world example:

http://wiki.nginx.org/NginxHttpHeadersMoreModule

(although a rewrite phase handler is also a bit different from an
access phase one, and even more so for 0.8.42+.)

> What is the best way to do
> this ? I would like to prevent any other modules from tampering with this
> header once it is set

This one is difficult to achieve. Anarchism is ubiquitous in the nginx world ;)

Hope this helps,
-agentzh

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

creating a response from the "access" phase

hassan.syed 3111 July 27, 2010 07:54AM

Re: creating a response from the "access" phase

agentzh 1525 August 09, 2010 10:52PM



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

Online Users

Guests: 253
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