]> git.ipfire.org Git - thirdparty/haproxy.git/commitdiff
MINOR: httpclient: httpclient_ended() returns 1 if the client ended
authorWilliam Lallemand <wlallemand@haproxy.org>
Tue, 21 Sep 2021 08:58:10 +0000 (10:58 +0200)
committerWilliam Lallemand <wlallemand@haproxy.org>
Fri, 24 Sep 2021 12:21:26 +0000 (14:21 +0200)
httpclient_ended() returns 1 if there is no more data to collect,
because the client received everything or the connection ended.

include/haproxy/http_client-t.h
include/haproxy/http_client.h
src/http_client.c

index 079afdc08c8cc73e0e373a1be6ca8a00a6fa6d1c..611d56829d0c0f35cf87150e8c029caec6073ed1 100644 (file)
@@ -27,8 +27,11 @@ struct httpclient {
        struct sockaddr_storage dst;          /* destination address */
        struct appctx *appctx;                /* HTTPclient appctx */
        void *caller;                         /* ptr of the caller */
+       unsigned int flags;                   /* other flags */
 };
 
+#define    HTTPCLIENT_F_ENDED        0x00000001
+
 /* States of the HTTP Client Appctx */
 enum {
        HTTPCLIENT_S_REQ = 0,
index af7a17e3427cbb479f9b02b60a59fbf76eb79008..e4f6fb04c440f0e2c1e94439c28a555661c191fe 100644 (file)
@@ -17,4 +17,10 @@ static inline int httpclient_data(struct httpclient *hc)
        return b_data(&hc->res.buf);
 }
 
+/* Return 1 if the httpclient ended and won't receive any new data */
+static inline int httpclient_ended(struct httpclient *hc)
+{
+       return !!(hc->flags & HTTPCLIENT_F_ENDED);
+}
+
 #endif /* ! _HAPROXY_HTTCLIENT_H */
index d6889366e3e39554f99b3b4c5160ef1d550563c9..bafeafcacd3c78b00bea3d37eb4df43a189ea139 100644 (file)
@@ -559,10 +559,12 @@ static void httpclient_applet_io_handler(struct appctx *appctx)
 
                                        /* if there is no HTX data anymore and the EOM flag is
                                         * set, leave (no body) */
-                                       if (htx_is_empty(htx) && htx->flags & HTX_FL_EOM)
+                                       if (htx_is_empty(htx) && htx->flags & HTX_FL_EOM) {
                                                appctx->st0 = HTTPCLIENT_S_RES_END;
-                                       else
+                                               hc->flags |= HTTPCLIENT_F_ENDED;
+                                       } else {
                                                appctx->st0 = HTTPCLIENT_S_RES_BODY;
+                                       }
                                }
                        break;
 
@@ -648,6 +650,8 @@ static void httpclient_applet_release(struct appctx *appctx)
 {
        struct httpclient *hc = appctx->ctx.httpclient.ptr;
 
+       /* mark the httpclient as ended */
+       hc->flags |= HTTPCLIENT_F_ENDED;
        /* the applet is leaving, remove the ptr so we don't try to call it
         * again from the caller */
        hc->appctx = NULL;