]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http-ana: Rely on http_reply_and_close() to handle server error
authorChristopher Faulet <cfaulet@haproxy.com>
Mon, 27 Jan 2020 14:32:25 +0000 (15:32 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 6 Feb 2020 13:55:34 +0000 (14:55 +0100)
The http_server_error() function now relies on http_reply_and_close(). Both do
almost the same actions. In addtion, http_server_error() sets the error flag and
the final state flag on the stream.

include/proto/http_ana.h
src/http_ana.c

index 6bef553c9e830b0d51f05d2714e99557641585f5..57fd881b528c6edf31f5b818596f639ddd5f94f8 100644 (file)
@@ -48,7 +48,7 @@ void http_check_request_for_cacheability(struct stream *s, struct channel *req);
 void http_check_response_for_cacheability(struct stream *s, struct channel *res);
 void http_perform_server_redirect(struct stream *s, struct stream_interface *si);
 void http_server_error(struct stream *s, struct stream_interface *si, int err, int finst, const struct buffer *msg);
-void http_reply_and_close(struct stream *s, short status, struct buffer *msg);
+void http_reply_and_close(struct stream *s, short status, const struct buffer *msg);
 void http_return_srv_error(struct stream *s, struct stream_interface *si);
 struct buffer *http_error_message(struct stream *s);
 
index eb260056da934631361f927c4244148fb07533e2..2ef4b39b33875b822e04ad375535db80629fab6e 100644 (file)
@@ -4550,45 +4550,25 @@ static void http_end_response(struct stream *s)
 void http_server_error(struct stream *s, struct stream_interface *si, int err,
                       int finst, const struct buffer *msg)
 {
-       channel_auto_read(si_oc(si));
-       channel_abort(si_oc(si));
-       channel_auto_close(si_oc(si));
-       channel_htx_erase(si_oc(si), htxbuf(&(si_oc(si))->buf));
-       channel_htx_truncate(si_ic(si), htxbuf(&(si_ic(si))->buf));
-       channel_auto_close(si_ic(si));
-       channel_auto_read(si_ic(si));
-
-       /* <msg> is an HTX structure. So we copy it in the response's
-        * channel */
-       if (msg && !b_is_null(msg)) {
-               struct channel *chn = si_ic(si);
-               struct htx *htx;
-               size_t data;
-
-               FLT_STRM_CB(s, flt_http_reply(s, s->txn->status, msg));
-               htx = htx_from_buf(&chn->buf);
-               if (channel_htx_copy_msg(chn, htx, msg)) {
-                       htx->flags |= HTX_FL_PROXY_RESP;
-                       data = htx->data - co_data(chn);
-                       c_adv(chn, data);
-                       htx->first = -1;
-                       chn->total += data;
-               }
-       }
+       http_reply_and_close(s, s->txn->status, msg);
        if (!(s->flags & SF_ERR_MASK))
                s->flags |= err;
        if (!(s->flags & SF_FINST_MASK))
                s->flags |= finst;
 }
 
-void http_reply_and_close(struct stream *s, short status, struct buffer *msg)
+void http_reply_and_close(struct stream *s, short status, const struct buffer *msg)
 {
        channel_auto_read(&s->req);
        channel_abort(&s->req);
        channel_auto_close(&s->req);
        channel_htx_erase(&s->req, htxbuf(&s->req.buf));
        channel_htx_truncate(&s->res, htxbuf(&s->res.buf));
+       channel_auto_read(&s->res);
+       channel_auto_close(&s->res);
+       channel_shutr_now(&s->res);
 
+       s->res.wex = tick_add_ifset(now_ms, s->res.wto);
        s->txn->flags &= ~TX_WAIT_NEXT_RQ;
 
        /* <msg> is an HTX structure. So we copy it in the response's
@@ -4608,11 +4588,6 @@ void http_reply_and_close(struct stream *s, short status, struct buffer *msg)
                        chn->total += data;
                }
        }
-
-       s->res.wex = tick_add_ifset(now_ms, s->res.wto);
-       channel_auto_read(&s->res);
-       channel_auto_close(&s->res);
-       channel_shutr_now(&s->res);
 }
 
 struct buffer *http_error_message(struct stream *s)