How to redirect 302 in code?

the following code does not work in nginx-0.8.6,who can tell me why? thx

location = ngx_palloc(r->pool, strlen(url));

r->headers_out.location = ngx_palloc(r->pool,
sizeof(ngx_table_elt_t));

ngx_copy(location, url, strlen(url));
r->headers_out.location->value.data = location;
r->headers_out.location->value.len = strlen(url);
r->headers_out.content_length_n = 0;
r->header_only = 1;
r->keepalive = 0;
return NGX_HTTP_MOVED_TEMPORARILY ;

Posted at Nginx Forum:

At Tue, 25 Aug 2009 09:04:09 -0400,
“wangbin579” [email protected] wrote:

Ok. Follow code work:

header = ngx_list_push(&r->headers_out.headers);
if (header == NULL) {
return NGX_HTTP_INTERNAL_SERVER_ERROR;
}

header->hash = 1;
header->key.len = sizeof(“Location”) - 1;
header->key.data = (u_char *) “Location”;
header->value.len = sizeof(“http://google.com/”) - 1;
header->value.data = (u_char *) “http://google.com/” - 1;

return NGX_HTTP_MOVED_TEMPORARILY;

wow,it works
thanks

Posted at Nginx Forum: