creating a response from the "access" phase
agentzh
agentzh at gmail.com
Tue Aug 10 06:51:14 MSD 2010
On Tue, Jul 27, 2010 at 7:52 PM, Hassan Syed <h.a.syed at 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
More information about the nginx-devel
mailing list