# The keepalive problem when using redirection in code

**URL:** <https://www.ruby-forum.com/t/the-keepalive-problem-when-using-redirection-in-code/177708>\
**Category:** NGINX\
**Created:** [October 22, 2009, 11:44am UTC](https://www.ruby-forum.com/t/the-keepalive-problem-when-using-redirection-in-code/177708 "2009-10-22T11:44:47Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![wangbin579](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/bc79bd/32.png) [@wangbin579](https://www.ruby-forum.com/u/wangbin579)\
**Post date:** [October 22, 2009, 11:44am UTC](https://www.ruby-forum.com/t/the-keepalive-problem-when-using-redirection-in-code/177708/1 "2009-10-22T11:44:47Z")

</div>

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:

> **[the keepalive problem when using redirection in code](https://forum.nginx.org/read.php?2,15805,15805#msg-15805)**
>
> 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);...

---

<div class="post-metadata">

**Author:** ![wangbin579](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/bc79bd/32.png) [@wangbin579](https://www.ruby-forum.com/u/wangbin579)\
**Post date:** [October 22, 2009, 11:46am UTC](https://www.ruby-forum.com/t/the-keepalive-problem-when-using-redirection-in-code/177708/2 "2009-10-22T11:46:33Z")

</div>

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

Posted at Nginx Forum:

> **[Re: the keepalive problem when using redirection in code](https://forum.nginx.org/read.php?2,15805,15808#msg-15808)**
>
> 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);...

---

<div class="post-metadata">

**Author:** ![wangbin579](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/bc79bd/32.png) [@wangbin579](https://www.ruby-forum.com/u/wangbin579)\
**Post date:** [October 22, 2009, 11:59am UTC](https://www.ruby-forum.com/t/the-keepalive-problem-when-using-redirection-in-code/177708/3 "2009-10-22T11:59:25Z")

</div>

r-\>zero\_body=1;???

Posted at Nginx Forum:

> **[Re: the keepalive problem when using redirection in code](https://forum.nginx.org/read.php?2,15805,15815#msg-15815)**
>
> 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);...

---

<div class="post-metadata">

**Author:** ![wangbin579](https://www.ruby-forum.com/letter_avatar_proxy/v4/letter/w/bc79bd/32.png) [@wangbin579](https://www.ruby-forum.com/u/wangbin579)\
**Post date:** [October 22, 2009, 12:09pm UTC](https://www.ruby-forum.com/t/the-keepalive-problem-when-using-redirection-in-code/177708/4 "2009-10-22T12:09:58Z")

</div>

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.
