Welcome! Log In Create A New Profile

Advanced

returning a 302 from ACCESS_PHASE handler

Michael Ellery
September 10, 2013 05:38PM
Hello,

I have an ACCESS_PHASE handler and, in some cases, I want to return a 302 to a different domain. I'm currently doing
the following:

<code>
ngx_table_elt_t *set_location = ngx_list_push(&r->headers_out.headers);
if (set_location == NULL) {
SXEL2("ERROR: failed to add location header");
return -1;
}

r->err_status = NGX_HTTP_MOVED_TEMPORARILY;

set_location->hash = 1;
ngx_str_set(&set_location->key, "Location");
set_location->value.len = len;
set_location->value.data = location;

ngx_http_clear_location(r);

ngx_http_finalize_request(r, NGX_HTTP_MOVED_TEMPORARILY);

</code>

and then returning NGX_OK from my handler.

This seems to work in the sense that I do get the expected 302 at my client - HOWEVER, I also get a segfault:

2013/09/10 13:26:22 [alert] 28910#0: worker process 29362 exited on signal 11

....which seems to be happening at ngx_http_proxy_module.c:645

ngx_http_set_ctx(r, ctx, ngx_http_proxy_module);

because r->ctx is NULL at this point.

I suspect that calling ngx_http_finalize_request from my handler is causing this, although I have not conclusively
proven this.

Does someone know if it's possible to return a redirect from ACCESS handlers and, if so, what is the proper way to
accomplish it?

TIA,
Mike Ellery

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

returning a 302 from ACCESS_PHASE handler

Michael Ellery 926 September 10, 2013 05:38PM

Re:returning a 302 from ACCESS_PHASE handler

flygoast 569 September 10, 2013 09:52PM

Re: returning a 302 from ACCESS_PHASE handler

Maxim Dounin 442 September 11, 2013 07:36AM



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

Online Users

Guests: 157
Record Number of Users: 8 on April 13, 2023
Record Number of Guests: 500 on July 15, 2024
Powered by nginx      Powered by FreeBSD      PHP Powered      Powered by MariaDB      ipv6 ready