Hi Ciprian,

On Wed, Jan 11, 2017 at 12:58:57AM +0200, Ciprian Dorin Craciun wrote:
> On Tue, Jan 10, 2017 at 9:36 AM, Cyril Bonté <cyril.bo...@free.fr> wrote:
> > This is because haproxy behaves differently depending on the the Location
> > URL :
> > - beginning with /, it will allow HTTP keep-alived connections (Location:
> > /redir/foo)
> > - otherwise it unconditionnally won't, and there's no option to change this
> > (Location: http://mysite/redir)
> 
> 
> 
> 
> Quickly looking through the latest HAProxy code on the 1.7 branch, I
> think I found the piece of code which is responsible for closing the
> connections on redirects that do not start with `/`:
> 
> 
> ~~~~ [starting with line 4225] ~~~~
>     if (*location == '/' &&
>         (req->flags & HTTP_MSGF_XFER_LEN) &&
>         ((!(req->flags & HTTP_MSGF_TE_CHNK) && !req->body_len) ||
> (req->msg_state == HTTP_MSG_DONE)) &&
>         ((txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_SCL ||
>          (txn->flags & TX_CON_WANT_MSK) == TX_CON_WANT_KAL)) {
>         /* keep-alive possible */
> ~~~~
> 
> 
> (This also explains why protocol-relative URL's (i.e.
> `//some-domain.com/...`) work.)
> 
> Thus if I were to patch my HAProxy build to eliminate the just the
> `*location == '/'` expression, I would obtain keep-alive regardless of
> where I redirect the browser.
> 
> Could someone more experienced in the HAProxy source code advise if
> this is the only place I should give a look?

Yes that's indeed the place. The reason for this behaviour is that
(normally) when the client gets a redirect to another host or scheme,
it will no longer use the current connection and will have to close
it. The typical use case is when redirecting from HTTP to HTTPS, you
definitely don't want to keep the connection active on port 80 since
it will not be used anymore.

But maybe your use case is different and that's something we should
revisit or make a bit more configurable ?

Willy

Reply via email to