MINOR: httpclient: Make the CLI flags public for future use

Those flags used by the http_client in its CLI function might come to
use for OCSP updates that will strongly rely on the http client.
This commit is contained in:
Remi Tricot-Le Breton 2022-12-20 11:11:03 +01:00 committed by William Lallemand
parent 2b96364b35
commit 95e7cf1ddf
2 changed files with 19 additions and 18 deletions

View File

@ -59,4 +59,11 @@ enum {
#define HTTPCLIENT_USERAGENT "HAProxy"
/* What kind of data we need to read */
#define HC_F_RES_STLINE 0x01
#define HC_F_RES_HDR 0x02
#define HC_F_RES_BODY 0x04
#define HC_F_RES_END 0x08
#endif /* ! _HAPROXY_HTTCLIENT__T_H */

View File

@ -59,12 +59,6 @@ static char *resolvers_prefer = NULL;
* The functions will be starting by "hc_cli" for "httpclient cli"
*/
/* What kind of data we need to read */
#define HC_CLI_F_RES_STLINE 0x01
#define HC_CLI_F_RES_HDR 0x02
#define HC_CLI_F_RES_BODY 0x04
#define HC_CLI_F_RES_END 0x08
/* the CLI context for the httpclient command */
struct hcli_svc_ctx {
struct httpclient *hc; /* the httpclient instance */
@ -83,7 +77,7 @@ void hc_cli_res_stline_cb(struct httpclient *hc)
return;
ctx = appctx->svcctx;
ctx->flags |= HC_CLI_F_RES_STLINE;
ctx->flags |= HC_F_RES_STLINE;
appctx_wakeup(appctx);
}
@ -96,7 +90,7 @@ void hc_cli_res_headers_cb(struct httpclient *hc)
return;
ctx = appctx->svcctx;
ctx->flags |= HC_CLI_F_RES_HDR;
ctx->flags |= HC_F_RES_HDR;
appctx_wakeup(appctx);
}
@ -109,7 +103,7 @@ void hc_cli_res_body_cb(struct httpclient *hc)
return;
ctx = appctx->svcctx;
ctx->flags |= HC_CLI_F_RES_BODY;
ctx->flags |= HC_F_RES_BODY;
appctx_wakeup(appctx);
}
@ -122,7 +116,7 @@ void hc_cli_res_end_cb(struct httpclient *hc)
return;
ctx = appctx->svcctx;
ctx->flags |= HC_CLI_F_RES_END;
ctx->flags |= HC_F_RES_END;
appctx_wakeup(appctx);
}
@ -197,15 +191,15 @@ static int hc_cli_io_handler(struct appctx *appctx)
struct httpclient *hc = ctx->hc;
struct http_hdr *hdrs, *hdr;
if (ctx->flags & HC_CLI_F_RES_STLINE) {
if (ctx->flags & HC_F_RES_STLINE) {
chunk_printf(&trash, "%.*s %d %.*s\n", (unsigned int)istlen(hc->res.vsn), istptr(hc->res.vsn),
hc->res.status, (unsigned int)istlen(hc->res.reason), istptr(hc->res.reason));
if (applet_putchk(appctx, &trash) == -1)
goto more;
ctx->flags &= ~HC_CLI_F_RES_STLINE;
ctx->flags &= ~HC_F_RES_STLINE;
}
if (ctx->flags & HC_CLI_F_RES_HDR) {
if (ctx->flags & HC_F_RES_HDR) {
chunk_reset(&trash);
hdrs = hc->res.hdrs;
for (hdr = hdrs; isttest(hdr->v); hdr++) {
@ -216,10 +210,10 @@ static int hc_cli_io_handler(struct appctx *appctx)
goto too_many_hdrs;
if (applet_putchk(appctx, &trash) == -1)
goto more;
ctx->flags &= ~HC_CLI_F_RES_HDR;
ctx->flags &= ~HC_F_RES_HDR;
}
if (ctx->flags & HC_CLI_F_RES_BODY) {
if (ctx->flags & HC_F_RES_BODY) {
int ret;
ret = httpclient_res_xfer(hc, sc_ib(sc));
@ -228,12 +222,12 @@ static int hc_cli_io_handler(struct appctx *appctx)
/* remove the flag if the buffer was emptied */
if (httpclient_data(hc))
goto more;
ctx->flags &= ~HC_CLI_F_RES_BODY;
ctx->flags &= ~HC_F_RES_BODY;
}
/* we must close only if F_END is the last flag */
if (ctx->flags == HC_CLI_F_RES_END) {
ctx->flags &= ~HC_CLI_F_RES_END;
if (ctx->flags == HC_F_RES_END) {
ctx->flags &= ~HC_F_RES_END;
goto end;
}