]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: http-ana: Add a function for forward internal responses
authorChristopher Faulet <cfaulet@haproxy.com>
Tue, 28 Jan 2020 08:26:19 +0000 (09:26 +0100)
committerChristopher Faulet <cfaulet@haproxy.com>
Thu, 6 Feb 2020 13:55:34 +0000 (14:55 +0100)
Operations performed when internal responses (redirect/deny/auth/errors) are
returned are always the same. The http_forward_proxy_resp() function is added to
group all of them under a unique function.

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

index 57fd881b528c6edf31f5b818596f639ddd5f94f8..2b35388b14d9d610d564f14eea47d79ce0d557b9 100644 (file)
@@ -51,6 +51,7 @@ void http_server_error(struct stream *s, struct stream_interface *si, int err, i
 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);
+int http_forward_proxy_resp(struct stream *s, int final);
 
 struct http_txn *http_alloc_txn(struct stream *s);
 void http_init_txn(struct stream *s);
index 2ef4b39b33875b822e04ad375535db80629fab6e..d2afd2ab035d64a31ce9af69148fca4199e826b8 100644 (file)
@@ -4547,6 +4547,40 @@ static void http_end_response(struct stream *s)
        DBG_TRACE_LEAVE(STRM_EV_HTTP_ANA, s, txn);
 }
 
+/* Forward a response generated by HAProxy (error/redirect/return). This
+ * function forwards all pending incoming data. If <final> is set to 0, nothing
+ * more is performed. It is used for 1xx informational messages. Otherwise, the
+ * transaction is terminated and the request is emptied. On success 1 is
+ * returned. If an error occurred, 0 is returned.
+ */
+int http_forward_proxy_resp(struct stream *s, int final)
+{
+       struct channel *req = &s->req;
+       struct channel *res = &s->res;
+       struct htx *htx = htxbuf(&res->buf);
+       size_t data;
+
+       if (final) {
+               htx->flags |= HTX_FL_PROXY_RESP;
+
+               channel_auto_read(req);
+               channel_abort(req);
+               channel_auto_close(req);
+               channel_htx_erase(req, htxbuf(&req->buf));
+
+               res->wex = tick_add_ifset(now_ms, res->wto);
+               channel_auto_read(res);
+               channel_auto_close(res);
+               channel_shutr_now(res);
+       }
+
+       data = htx->data - co_data(res);
+       c_adv(res, data);
+       htx->first = -1;
+       res->total += data;
+       return 1;
+}
+
 void http_server_error(struct stream *s, struct stream_interface *si, int err,
                       int finst, const struct buffer *msg)
 {