]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
[MINOR] http: detect connection: close earlier
authorWilly Tarreau <w@1wt.eu>
Sat, 17 Oct 2009 18:12:21 +0000 (20:12 +0200)
committerWilly Tarreau <w@1wt.eu>
Sat, 17 Oct 2009 18:15:29 +0000 (20:15 +0200)
Till now we would only set SN_CONN_CLOSED after rewriting it. Now we
set it just after checking the Connection header so that we can use
the result later if required.

src/proto_http.c

index 23007384310f33376d2c2203dbd42d286389f882..a68335ca0ca5ce80019e94649954fd707627eb11 100644 (file)
@@ -2166,6 +2166,12 @@ int http_process_req_common(struct session *s, struct buffer *req, int an_bit, s
                        }
                        old_idx = cur_idx;
                }
+
+               /* if there was no Connection header and we're in HTTP/1.0, then "close" is implied */
+               if (!(s->flags & SN_CONN_CLOSED) && (msg->sl.rq.v_l == 8) &&
+                   (req->data[msg->som + msg->sl.rq.v + 5] == '1') &&
+                   (req->data[msg->som + msg->sl.rq.v + 7] == '0'))
+                       s->flags |= SN_CONN_CLOSED;
        }
        /* add request headers from the rule sets in the same order */
        for (cur_idx = 0; cur_idx < px->nb_reqadd; cur_idx++) {
@@ -2498,15 +2504,10 @@ int http_process_request(struct session *s, struct buffer *req, int an_bit)
                }
        }
 
-       /*
-        * 11: add "Connection: close" if needed and not yet set.
-        * Note that we do not need to add it in case of HTTP/1.0.
-        */
+       /* 11: add "Connection: close" if needed and not yet set. */
        if (!(s->flags & SN_CONN_CLOSED) &&
            ((s->fe->options | s->be->options) & (PR_O_HTTP_CLOSE|PR_O_FORCE_CLO))) {
-               if ((unlikely(msg->sl.rq.v_l != 8) ||
-                    unlikely(req->data[msg->som + msg->sl.rq.v + 7] != '0')) &&
-                   unlikely(http_header_add_tail2(req, &txn->req, &txn->hdr_idx,
+               if (unlikely(http_header_add_tail2(req, &txn->req, &txn->hdr_idx,
                                                   "Connection: close", 17)) < 0)
                        goto return_bad_req;
                s->flags |= SN_CONN_CLOSED;