From 1123dde6dd31a09ffcf173513b0282d03cf62793 Mon Sep 17 00:00:00 2001 From: William Lallemand Date: Tue, 21 Sep 2021 10:58:10 +0200 Subject: [PATCH] MINOR: httpclient: httpclient_ended() returns 1 if the client ended 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 | 3 +++ include/haproxy/http_client.h | 6 ++++++ src/http_client.c | 8 ++++++-- 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/include/haproxy/http_client-t.h b/include/haproxy/http_client-t.h index 079afdc..611d568 100644 --- a/include/haproxy/http_client-t.h +++ b/include/haproxy/http_client-t.h @@ -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, diff --git a/include/haproxy/http_client.h b/include/haproxy/http_client.h index af7a17e..e4f6fb0 100644 --- a/include/haproxy/http_client.h +++ b/include/haproxy/http_client.h @@ -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 */ diff --git a/src/http_client.c b/src/http_client.c index d688936..bafeafc 100644 --- a/src/http_client.c +++ b/src/http_client.c @@ -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; -- 1.7.10.4