The keepalive problem when using redirection in code

the code is as the following:
header->hash = 1;
header->key.len = sizeof(“Location”) - 1;
header->key.data=(u_char ) “Location”;
header->value.len = strlen(param->redirectUrl);
header->value.data=(u_char
)param->redirectUrl;
r->header_only=1;
r->headers_out.content_length_n=0;
r->headers_out.content_type.len = sizeof(“text/html”) - 1;
r->headers_out.content_type.data = (u_char *) “text/html”;
r->headers_out.status = NGX_HTTP_OK;

return NGX_HTTP_MOVED_TEMPORARILY;

when using keepalive (65s),the http responce will return in more than
65s .

I use two methods

  1. if I send some contents back(so r->header_only=0),the phenomena is
    gone,the http responce return normally.
  2. If I set r->keepalive=0,the phenomena is also gone,the http responce
    return normally.

Are the above methods right?
thanks

Posted at Nginx Forum:

simply saying:
how can I send header only when using redirection under keepalive mode

Posted at Nginx Forum:

r->zero_body=1;???

Posted at Nginx Forum:

Hello!

On Thu, Oct 22, 2009 at 05:30:47AM -0400, wangbin579 wrote:

r->headers_out.status = NGX_HTTP_OK;

return NGX_HTTP_MOVED_TEMPORARILY;

when using keepalive (65s),the http responce will return in more than 65s .

I use two methods

  1. if I send some contents back(so r->header_only=0),the phenomena is gone,the http responce return normally.
  2. If I set r->keepalive=0,the phenomena is also gone,the http responce return normally.

Are the above methods right?

No, the above code breaks http standard as it returns response
without message body with 302 code to arbitrary requests. And
this is why it breaks keepalive connections.

Consult RFC 2616 for details.

Maxim D.