William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1 | /* |
| 2 | * HTTP Client |
| 3 | * |
| 4 | * Copyright (C) 2021 HAProxy Technologies, William Lallemand <wlallemand@haproxy.com> |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License |
| 8 | * as published by the Free Software Foundation; either version |
| 9 | * 2 of the License, or (at your option) any later version. |
| 10 | * |
| 11 | * This file implements an HTTP Client API. |
| 12 | * |
| 13 | */ |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 14 | |
William Lallemand | 2a8fe8b | 2021-08-20 14:25:15 +0200 | [diff] [blame] | 15 | #include <haproxy/api.h> |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 16 | #include <haproxy/applet.h> |
| 17 | #include <haproxy/cli.h> |
William Lallemand | cf5cb0b | 2022-04-22 14:48:45 +0200 | [diff] [blame] | 18 | #include <haproxy/ssl_ckch.h> |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 19 | #include <haproxy/dynbuf.h> |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 20 | #include <haproxy/cfgparse.h> |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 21 | #include <haproxy/global.h> |
William Lallemand | 0da616e | 2021-10-28 15:34:26 +0200 | [diff] [blame] | 22 | #include <haproxy/istbuf.h> |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 23 | #include <haproxy/h1_htx.h> |
| 24 | #include <haproxy/http.h> |
William Lallemand | 2b7dc4e | 2022-02-24 16:55:41 +0100 | [diff] [blame] | 25 | #include <haproxy/http_ana-t.h> |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 26 | #include <haproxy/http_client.h> |
| 27 | #include <haproxy/http_htx.h> |
William Lallemand | 5392ff6 | 2022-04-28 16:55:02 +0200 | [diff] [blame] | 28 | #include <haproxy/http_rules.h> |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 29 | #include <haproxy/htx.h> |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 30 | #include <haproxy/log.h> |
| 31 | #include <haproxy/proxy.h> |
William Lallemand | 5392ff6 | 2022-04-28 16:55:02 +0200 | [diff] [blame] | 32 | #include <haproxy/resolvers.h> |
Willy Tarreau | 5edca2f | 2022-05-27 09:25:10 +0200 | [diff] [blame] | 33 | #include <haproxy/sc_strm.h> |
William Lallemand | 2a8fe8b | 2021-08-20 14:25:15 +0200 | [diff] [blame] | 34 | #include <haproxy/server.h> |
Willy Tarreau | df3231c | 2022-09-02 09:02:21 +0200 | [diff] [blame] | 35 | #include <haproxy/ssl_sock.h> |
William Lallemand | 7f1df8f | 2022-04-14 17:50:20 +0200 | [diff] [blame] | 36 | #include <haproxy/sock_inet.h> |
Willy Tarreau | cb086c6 | 2022-05-27 09:47:12 +0200 | [diff] [blame] | 37 | #include <haproxy/stconn.h> |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 38 | #include <haproxy/tools.h> |
| 39 | |
| 40 | #include <string.h> |
| 41 | |
| 42 | |
| 43 | static struct proxy *httpclient_proxy; |
William Lallemand | 6fce46a | 2022-05-04 14:53:41 +0200 | [diff] [blame] | 44 | |
William Lallemand | 957ab13 | 2021-08-24 18:33:28 +0200 | [diff] [blame] | 45 | #ifdef USE_OPENSSL |
William Lallemand | 6fce46a | 2022-05-04 14:53:41 +0200 | [diff] [blame] | 46 | /* if the httpclient is not configured, error are ignored and features are limited */ |
| 47 | static int hard_error_ssl = 0; |
William Lallemand | f1344b3 | 2022-04-26 12:00:06 +0200 | [diff] [blame] | 48 | static int httpclient_ssl_verify = SSL_SOCK_VERIFY_REQUIRED; |
William Lallemand | 683fbb8 | 2022-05-04 15:43:01 +0200 | [diff] [blame] | 49 | static char *httpclient_ssl_ca_file = NULL; |
William Lallemand | 957ab13 | 2021-08-24 18:33:28 +0200 | [diff] [blame] | 50 | #endif |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 51 | static struct applet httpclient_applet; |
| 52 | |
William Lallemand | 7c5a7ef | 2022-05-04 15:59:44 +0200 | [diff] [blame] | 53 | /* if the httpclient is not configured, error are ignored and features are limited */ |
William Lallemand | 8a734cb | 2022-05-04 16:10:47 +0200 | [diff] [blame] | 54 | static int hard_error_resolvers = 0; |
| 55 | static char *resolvers_id = NULL; |
William Lallemand | 7c5a7ef | 2022-05-04 15:59:44 +0200 | [diff] [blame] | 56 | static char *resolvers_prefer = NULL; |
William Lallemand | eaa703e | 2022-04-22 17:52:33 +0200 | [diff] [blame] | 57 | |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 58 | /* --- This part of the file implement an HTTP client over the CLI --- |
| 59 | * The functions will be starting by "hc_cli" for "httpclient cli" |
| 60 | */ |
| 61 | |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 62 | /* What kind of data we need to read */ |
| 63 | #define HC_CLI_F_RES_STLINE 0x01 |
| 64 | #define HC_CLI_F_RES_HDR 0x02 |
| 65 | #define HC_CLI_F_RES_BODY 0x04 |
| 66 | #define HC_CLI_F_RES_END 0x08 |
| 67 | |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 68 | /* the CLI context for the httpclient command */ |
| 69 | struct hcli_svc_ctx { |
| 70 | struct httpclient *hc; /* the httpclient instance */ |
| 71 | uint flags; /* flags from HC_CLI_F_* above */ |
| 72 | }; |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 73 | |
| 74 | /* These are the callback used by the HTTP Client when it needs to notify new |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 75 | * data, we only sets a flag in the IO handler via the svcctx. |
| 76 | */ |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 77 | void hc_cli_res_stline_cb(struct httpclient *hc) |
| 78 | { |
| 79 | struct appctx *appctx = hc->caller; |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 80 | struct hcli_svc_ctx *ctx; |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 81 | |
William Lallemand | dfc3f89 | 2021-08-20 11:35:29 +0200 | [diff] [blame] | 82 | if (!appctx) |
| 83 | return; |
| 84 | |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 85 | ctx = appctx->svcctx; |
| 86 | ctx->flags |= HC_CLI_F_RES_STLINE; |
William Lallemand | dfc3f89 | 2021-08-20 11:35:29 +0200 | [diff] [blame] | 87 | appctx_wakeup(appctx); |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 88 | } |
| 89 | |
| 90 | void hc_cli_res_headers_cb(struct httpclient *hc) |
| 91 | { |
| 92 | struct appctx *appctx = hc->caller; |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 93 | struct hcli_svc_ctx *ctx; |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 94 | |
William Lallemand | dfc3f89 | 2021-08-20 11:35:29 +0200 | [diff] [blame] | 95 | if (!appctx) |
| 96 | return; |
| 97 | |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 98 | ctx = appctx->svcctx; |
| 99 | ctx->flags |= HC_CLI_F_RES_HDR; |
William Lallemand | dfc3f89 | 2021-08-20 11:35:29 +0200 | [diff] [blame] | 100 | appctx_wakeup(appctx); |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 101 | } |
| 102 | |
| 103 | void hc_cli_res_body_cb(struct httpclient *hc) |
| 104 | { |
| 105 | struct appctx *appctx = hc->caller; |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 106 | struct hcli_svc_ctx *ctx; |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 107 | |
William Lallemand | dfc3f89 | 2021-08-20 11:35:29 +0200 | [diff] [blame] | 108 | if (!appctx) |
| 109 | return; |
| 110 | |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 111 | ctx = appctx->svcctx; |
| 112 | ctx->flags |= HC_CLI_F_RES_BODY; |
William Lallemand | dfc3f89 | 2021-08-20 11:35:29 +0200 | [diff] [blame] | 113 | appctx_wakeup(appctx); |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 114 | } |
| 115 | |
| 116 | void hc_cli_res_end_cb(struct httpclient *hc) |
| 117 | { |
| 118 | struct appctx *appctx = hc->caller; |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 119 | struct hcli_svc_ctx *ctx; |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 120 | |
William Lallemand | dfc3f89 | 2021-08-20 11:35:29 +0200 | [diff] [blame] | 121 | if (!appctx) |
| 122 | return; |
| 123 | |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 124 | ctx = appctx->svcctx; |
| 125 | ctx->flags |= HC_CLI_F_RES_END; |
William Lallemand | dfc3f89 | 2021-08-20 11:35:29 +0200 | [diff] [blame] | 126 | appctx_wakeup(appctx); |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 127 | } |
| 128 | |
| 129 | /* |
| 130 | * Parse an httpclient keyword on the cli: |
| 131 | * httpclient <ID> <method> <URI> |
| 132 | */ |
| 133 | static int hc_cli_parse(char **args, char *payload, struct appctx *appctx, void *private) |
| 134 | { |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 135 | struct hcli_svc_ctx *ctx = applet_reserve_svcctx(appctx, sizeof(*ctx)); |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 136 | struct httpclient *hc; |
| 137 | char *err = NULL; |
| 138 | enum http_meth_t meth; |
| 139 | char *meth_str; |
| 140 | struct ist uri; |
William Lallemand | dec25c3 | 2021-10-25 19:48:37 +0200 | [diff] [blame] | 141 | struct ist body = IST_NULL; |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 142 | |
| 143 | if (!cli_has_level(appctx, ACCESS_LVL_ADMIN)) |
| 144 | return 1; |
| 145 | |
| 146 | if (!*args[1] || !*args[2]) { |
| 147 | memprintf(&err, ": not enough parameters"); |
| 148 | goto err; |
| 149 | } |
| 150 | |
| 151 | meth_str = args[1]; |
| 152 | uri = ist(args[2]); |
| 153 | |
William Lallemand | dec25c3 | 2021-10-25 19:48:37 +0200 | [diff] [blame] | 154 | if (payload) |
| 155 | body = ist(payload); |
| 156 | |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 157 | meth = find_http_meth(meth_str, strlen(meth_str)); |
| 158 | |
| 159 | hc = httpclient_new(appctx, meth, uri); |
| 160 | if (!hc) { |
| 161 | goto err; |
| 162 | } |
| 163 | |
| 164 | /* update the httpclient callbacks */ |
| 165 | hc->ops.res_stline = hc_cli_res_stline_cb; |
| 166 | hc->ops.res_headers = hc_cli_res_headers_cb; |
| 167 | hc->ops.res_payload = hc_cli_res_body_cb; |
| 168 | hc->ops.res_end = hc_cli_res_end_cb; |
| 169 | |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 170 | ctx->hc = hc; /* store the httpclient ptr in the applet */ |
| 171 | ctx->flags = 0; |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 172 | |
William Lallemand | bad9c8c | 2022-01-14 14:10:33 +0100 | [diff] [blame] | 173 | if (httpclient_req_gen(hc, hc->req.url, hc->req.meth, NULL, body) != ERR_NONE) |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 174 | goto err; |
| 175 | |
| 176 | |
| 177 | if (!httpclient_start(hc)) |
| 178 | goto err; |
| 179 | |
| 180 | return 0; |
| 181 | |
| 182 | err: |
| 183 | memprintf(&err, "Can't start the HTTP client%s.\n", err ? err : ""); |
| 184 | return cli_err(appctx, err); |
| 185 | } |
| 186 | |
| 187 | /* This function dumps the content of the httpclient receive buffer |
| 188 | * on the CLI output |
| 189 | * |
| 190 | * Return 1 when the processing is finished |
| 191 | * return 0 if it needs to be called again |
| 192 | */ |
| 193 | static int hc_cli_io_handler(struct appctx *appctx) |
| 194 | { |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 195 | struct hcli_svc_ctx *ctx = appctx->svcctx; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 196 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 197 | struct httpclient *hc = ctx->hc; |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 198 | struct http_hdr *hdrs, *hdr; |
| 199 | |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 200 | if (ctx->flags & HC_CLI_F_RES_STLINE) { |
Christopher Faulet | 0158bb2 | 2022-06-01 17:08:19 +0200 | [diff] [blame] | 201 | chunk_printf(&trash, "%.*s %d %.*s\n", (unsigned int)istlen(hc->res.vsn), istptr(hc->res.vsn), |
| 202 | hc->res.status, (unsigned int)istlen(hc->res.reason), istptr(hc->res.reason)); |
| 203 | if (applet_putchk(appctx, &trash) == -1) |
| 204 | goto more; |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 205 | ctx->flags &= ~HC_CLI_F_RES_STLINE; |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 206 | } |
| 207 | |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 208 | if (ctx->flags & HC_CLI_F_RES_HDR) { |
Christopher Faulet | 0158bb2 | 2022-06-01 17:08:19 +0200 | [diff] [blame] | 209 | chunk_reset(&trash); |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 210 | hdrs = hc->res.hdrs; |
| 211 | for (hdr = hdrs; isttest(hdr->v); hdr++) { |
Christopher Faulet | 0158bb2 | 2022-06-01 17:08:19 +0200 | [diff] [blame] | 212 | if (!h1_format_htx_hdr(hdr->n, hdr->v, &trash)) |
| 213 | goto too_many_hdrs; |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 214 | } |
Christopher Faulet | 0158bb2 | 2022-06-01 17:08:19 +0200 | [diff] [blame] | 215 | if (!chunk_memcat(&trash, "\r\n", 2)) |
| 216 | goto too_many_hdrs; |
| 217 | if (applet_putchk(appctx, &trash) == -1) |
| 218 | goto more; |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 219 | ctx->flags &= ~HC_CLI_F_RES_HDR; |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 220 | } |
| 221 | |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 222 | if (ctx->flags & HC_CLI_F_RES_BODY) { |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 223 | int ret; |
| 224 | |
Willy Tarreau | 475e463 | 2022-05-27 10:26:46 +0200 | [diff] [blame] | 225 | ret = httpclient_res_xfer(hc, sc_ib(sc)); |
| 226 | channel_add_input(sc_ic(sc), ret); /* forward what we put in the buffer channel */ |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 227 | |
Christopher Faulet | 0158bb2 | 2022-06-01 17:08:19 +0200 | [diff] [blame] | 228 | /* remove the flag if the buffer was emptied */ |
| 229 | if (httpclient_data(hc)) |
| 230 | goto more; |
| 231 | ctx->flags &= ~HC_CLI_F_RES_BODY; |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | /* we must close only if F_END is the last flag */ |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 235 | if (ctx->flags == HC_CLI_F_RES_END) { |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 236 | ctx->flags &= ~HC_CLI_F_RES_END; |
Christopher Faulet | 89f2626 | 2022-06-01 17:17:24 +0200 | [diff] [blame] | 237 | goto end; |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 238 | } |
| 239 | |
Christopher Faulet | 0158bb2 | 2022-06-01 17:08:19 +0200 | [diff] [blame] | 240 | more: |
| 241 | if (!ctx->flags) |
| 242 | applet_have_no_more_data(appctx); |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 243 | return 0; |
Christopher Faulet | 89f2626 | 2022-06-01 17:17:24 +0200 | [diff] [blame] | 244 | end: |
| 245 | return 1; |
Christopher Faulet | 0158bb2 | 2022-06-01 17:08:19 +0200 | [diff] [blame] | 246 | |
| 247 | too_many_hdrs: |
| 248 | return cli_err(appctx, "Too many headers.\n"); |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 249 | } |
| 250 | |
| 251 | static void hc_cli_release(struct appctx *appctx) |
| 252 | { |
Willy Tarreau | 89a7c41 | 2022-05-05 19:38:21 +0200 | [diff] [blame] | 253 | struct hcli_svc_ctx *ctx = appctx->svcctx; |
| 254 | struct httpclient *hc = ctx->hc; |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 255 | |
| 256 | /* Everything possible was printed on the CLI, we can destroy the client */ |
William Lallemand | ecb83e1 | 2021-09-28 11:00:43 +0200 | [diff] [blame] | 257 | httpclient_stop_and_destroy(hc); |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 258 | |
| 259 | return; |
| 260 | } |
| 261 | |
| 262 | /* register cli keywords */ |
| 263 | static struct cli_kw_list cli_kws = {{ },{ |
Willy Tarreau | 2c8f984 | 2022-02-18 16:26:36 +0100 | [diff] [blame] | 264 | { { "httpclient", NULL }, "httpclient <method> <URI> : launch an HTTP request", hc_cli_parse, hc_cli_io_handler, hc_cli_release, NULL, ACCESS_EXPERT}, |
William Lallemand | 03a4eb1 | 2021-08-18 16:46:21 +0200 | [diff] [blame] | 265 | { { NULL }, NULL, NULL, NULL } |
| 266 | }}; |
| 267 | |
| 268 | INITCALL1(STG_REGISTER, cli_register_kw, &cli_kws); |
| 269 | |
| 270 | |
| 271 | /* --- This part of the file implements the actual HTTP client API --- */ |
| 272 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 273 | /* |
| 274 | * Generate a simple request and fill the httpclient request buffer with it. |
| 275 | * The request contains a request line generated from the absolute <url> and |
| 276 | * <meth> as well as list of headers <hdrs>. |
| 277 | * |
| 278 | * If the buffer was filled correctly the function returns 0, if not it returns |
| 279 | * an error_code but there is no guarantee that the buffer wasn't modified. |
| 280 | */ |
William Lallemand | dec25c3 | 2021-10-25 19:48:37 +0200 | [diff] [blame] | 281 | int httpclient_req_gen(struct httpclient *hc, const struct ist url, enum http_meth_t meth, const struct http_hdr *hdrs, const struct ist payload) |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 282 | { |
| 283 | struct htx_sl *sl; |
| 284 | struct htx *htx; |
| 285 | int err_code = 0; |
| 286 | struct ist meth_ist, vsn; |
William Lallemand | dec25c3 | 2021-10-25 19:48:37 +0200 | [diff] [blame] | 287 | unsigned int flags = HTX_SL_F_VER_11 | HTX_SL_F_NORMALIZED_URI | HTX_SL_F_HAS_SCHM; |
William Lallemand | f03b53c | 2021-11-24 15:38:17 +0100 | [diff] [blame] | 288 | int i; |
William Lallemand | bad9c8c | 2022-01-14 14:10:33 +0100 | [diff] [blame] | 289 | int foundhost = 0, foundaccept = 0, foundua = 0; |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 290 | |
Christopher Faulet | 600985d | 2022-01-12 11:14:08 +0100 | [diff] [blame] | 291 | if (!b_alloc(&hc->req.buf)) |
| 292 | goto error; |
| 293 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 294 | if (meth >= HTTP_METH_OTHER) |
| 295 | goto error; |
| 296 | |
| 297 | meth_ist = http_known_methods[meth]; |
| 298 | |
| 299 | vsn = ist("HTTP/1.1"); |
| 300 | |
| 301 | htx = htx_from_buf(&hc->req.buf); |
| 302 | if (!htx) |
| 303 | goto error; |
William Lallemand | e1e045f | 2022-01-14 14:08:34 +0100 | [diff] [blame] | 304 | |
| 305 | if (!hc->ops.req_payload && !isttest(payload)) |
| 306 | flags |= HTX_SL_F_BODYLESS; |
| 307 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 308 | sl = htx_add_stline(htx, HTX_BLK_REQ_SL, flags, meth_ist, url, vsn); |
| 309 | if (!sl) { |
| 310 | goto error; |
| 311 | } |
| 312 | sl->info.req.meth = meth; |
| 313 | |
William Lallemand | f03b53c | 2021-11-24 15:38:17 +0100 | [diff] [blame] | 314 | for (i = 0; hdrs && hdrs[i].n.len; i++) { |
| 315 | /* Don't check the value length because a header value may be empty */ |
| 316 | if (isttest(hdrs[i].v) == 0) |
| 317 | continue; |
| 318 | |
| 319 | if (isteqi(hdrs[i].n, ist("host"))) |
| 320 | foundhost = 1; |
William Lallemand | bad9c8c | 2022-01-14 14:10:33 +0100 | [diff] [blame] | 321 | else if (isteqi(hdrs[i].n, ist("accept"))) |
| 322 | foundaccept = 1; |
| 323 | else if (isteqi(hdrs[i].n, ist("user-agent"))) |
| 324 | foundua = 1; |
William Lallemand | f03b53c | 2021-11-24 15:38:17 +0100 | [diff] [blame] | 325 | |
| 326 | if (!htx_add_header(htx, hdrs[i].n, hdrs[i].v)) |
| 327 | goto error; |
| 328 | } |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 329 | |
William Lallemand | f03b53c | 2021-11-24 15:38:17 +0100 | [diff] [blame] | 330 | if (!foundhost) { |
| 331 | /* Add Host Header from URL */ |
| 332 | if (!htx_add_header(htx, ist("Host"), ist("h"))) |
William Lallemand | 79a3478 | 2021-09-20 16:19:15 +0200 | [diff] [blame] | 333 | goto error; |
William Lallemand | f03b53c | 2021-11-24 15:38:17 +0100 | [diff] [blame] | 334 | if (!http_update_host(htx, sl, url)) |
William Lallemand | 79a3478 | 2021-09-20 16:19:15 +0200 | [diff] [blame] | 335 | goto error; |
| 336 | } |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 337 | |
William Lallemand | bad9c8c | 2022-01-14 14:10:33 +0100 | [diff] [blame] | 338 | if (!foundaccept) { |
| 339 | if (!htx_add_header(htx, ist("Accept"), ist("*/*"))) |
| 340 | goto error; |
| 341 | } |
| 342 | |
| 343 | if (!foundua) { |
| 344 | if (!htx_add_header(htx, ist("User-Agent"), ist(HTTPCLIENT_USERAGENT))) |
| 345 | goto error; |
| 346 | } |
| 347 | |
| 348 | |
William Lallemand | f03b53c | 2021-11-24 15:38:17 +0100 | [diff] [blame] | 349 | if (!htx_add_endof(htx, HTX_BLK_EOH)) |
| 350 | goto error; |
| 351 | |
William Lallemand | dec25c3 | 2021-10-25 19:48:37 +0200 | [diff] [blame] | 352 | if (isttest(payload)) { |
| 353 | /* add the payload if it can feat in the buffer, no need to set |
| 354 | * the Content-Length, the data will be sent chunked */ |
| 355 | if (!htx_add_data_atonce(htx, payload)) |
| 356 | goto error; |
| 357 | } |
| 358 | |
William Lallemand | 0da616e | 2021-10-28 15:34:26 +0200 | [diff] [blame] | 359 | /* If req.payload was set, does not set the end of stream which *MUST* |
| 360 | * be set in the callback */ |
| 361 | if (!hc->ops.req_payload) |
| 362 | htx->flags |= HTX_FL_EOM; |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 363 | |
| 364 | htx_to_buf(htx, &hc->req.buf); |
| 365 | |
| 366 | return 0; |
| 367 | error: |
| 368 | err_code |= ERR_ALERT | ERR_ABORT; |
| 369 | return err_code; |
| 370 | } |
| 371 | |
| 372 | /* |
| 373 | * transfer the response to the destination buffer and wakeup the HTTP client |
| 374 | * applet so it could fill again its buffer. |
| 375 | * |
Ilya Shipitsin | bd6b4be | 2021-10-15 16:18:21 +0500 | [diff] [blame] | 376 | * Return the number of bytes transferred. |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 377 | */ |
| 378 | int httpclient_res_xfer(struct httpclient *hc, struct buffer *dst) |
| 379 | { |
Willy Tarreau | 11adb1d | 2022-02-18 17:28:25 +0100 | [diff] [blame] | 380 | size_t room = b_room(dst); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 381 | int ret; |
| 382 | |
Willy Tarreau | 11adb1d | 2022-02-18 17:28:25 +0100 | [diff] [blame] | 383 | ret = b_force_xfer(dst, &hc->res.buf, MIN(room, b_data(&hc->res.buf))); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 384 | /* call the client once we consumed all data */ |
Christopher Faulet | 600985d | 2022-01-12 11:14:08 +0100 | [diff] [blame] | 385 | if (!b_data(&hc->res.buf)) { |
| 386 | b_free(&hc->res.buf); |
| 387 | if (hc->appctx) |
| 388 | appctx_wakeup(hc->appctx); |
| 389 | } |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 390 | return ret; |
| 391 | } |
| 392 | |
| 393 | /* |
William Lallemand | 0da616e | 2021-10-28 15:34:26 +0200 | [diff] [blame] | 394 | * Transfer raw HTTP payload from src, and insert it into HTX format in the |
| 395 | * httpclient. |
| 396 | * |
| 397 | * Must be used to transfer the request body. |
| 398 | * Then wakeup the httpclient so it can transfer it. |
| 399 | * |
| 400 | * <end> tries to add the ending data flag if it succeed to copy all data. |
| 401 | * |
| 402 | * Return the number of bytes copied from src. |
| 403 | */ |
| 404 | int httpclient_req_xfer(struct httpclient *hc, struct ist src, int end) |
| 405 | { |
| 406 | int ret = 0; |
| 407 | struct htx *htx; |
| 408 | |
Christopher Faulet | 600985d | 2022-01-12 11:14:08 +0100 | [diff] [blame] | 409 | if (!b_alloc(&hc->req.buf)) |
| 410 | goto error; |
| 411 | |
William Lallemand | 0da616e | 2021-10-28 15:34:26 +0200 | [diff] [blame] | 412 | htx = htx_from_buf(&hc->req.buf); |
| 413 | if (!htx) |
| 414 | goto error; |
| 415 | |
| 416 | if (hc->appctx) |
| 417 | appctx_wakeup(hc->appctx); |
| 418 | |
| 419 | ret += htx_add_data(htx, src); |
| 420 | |
| 421 | |
| 422 | /* if we copied all the data and the end flag is set */ |
| 423 | if ((istlen(src) == ret) && end) { |
Christopher Faulet | 48005de | 2022-10-14 15:10:24 +0200 | [diff] [blame] | 424 | /* no more data are expected. If the HTX buffer is empty, be |
| 425 | * sure to add something (EOT block in this case) to have |
| 426 | * something to send. It is important to be sure the EOM flags |
| 427 | * will be handled by the endpoint. Because the message is |
| 428 | * empty, this should not fail. Otherwise it is an error |
| 429 | */ |
| 430 | if (htx_is_empty(htx)) { |
| 431 | if (!htx_add_endof(htx, HTX_BLK_EOT)) |
| 432 | goto error; |
| 433 | } |
William Lallemand | 0da616e | 2021-10-28 15:34:26 +0200 | [diff] [blame] | 434 | htx->flags |= HTX_FL_EOM; |
| 435 | } |
| 436 | htx_to_buf(htx, &hc->req.buf); |
| 437 | |
| 438 | error: |
| 439 | |
| 440 | return ret; |
| 441 | } |
| 442 | |
William Lallemand | b4a4ef6 | 2022-02-23 14:18:16 +0100 | [diff] [blame] | 443 | /* Set the 'timeout server' in ms for the next httpclient request */ |
| 444 | void httpclient_set_timeout(struct httpclient *hc, int timeout) |
| 445 | { |
| 446 | hc->timeout_server = timeout; |
| 447 | } |
| 448 | |
William Lallemand | 7b2e0ee | 2022-02-17 19:10:55 +0100 | [diff] [blame] | 449 | /* |
| 450 | * Sets a destination for the httpclient from an HAProxy addr format |
| 451 | * This will prevent to determine the destination from the URL |
| 452 | * Return 0 in case of success or -1 otherwise. |
| 453 | */ |
| 454 | int httpclient_set_dst(struct httpclient *hc, const char *dst) |
| 455 | { |
| 456 | struct sockaddr_storage *sk; |
| 457 | char *errmsg = NULL; |
| 458 | |
| 459 | sockaddr_free(&hc->dst); |
| 460 | /* 'sk' is statically allocated (no need to be freed). */ |
| 461 | sk = str2sa_range(dst, NULL, NULL, NULL, NULL, NULL, |
| 462 | &errmsg, NULL, NULL, |
| 463 | PA_O_PORT_OK | PA_O_STREAM | PA_O_XPRT | PA_O_CONNECT); |
| 464 | if (!sk) { |
| 465 | ha_alert("httpclient: Failed to parse destination address in %s\n", errmsg); |
| 466 | free(errmsg); |
| 467 | return -1; |
| 468 | } |
| 469 | |
| 470 | if (!sockaddr_alloc(&hc->dst, sk, sizeof(*sk))) { |
| 471 | ha_alert("httpclient: Failed to allocate sockaddr in %s:%d.\n", __FUNCTION__, __LINE__); |
| 472 | return -1; |
| 473 | } |
| 474 | |
| 475 | return 0; |
| 476 | } |
William Lallemand | 0da616e | 2021-10-28 15:34:26 +0200 | [diff] [blame] | 477 | |
| 478 | /* |
Thierry Fournier | 74a9eb5 | 2022-10-10 12:46:38 +0200 | [diff] [blame] | 479 | * Split <url> in <scheme>, <host>, <port> |
William Lallemand | 7f1df8f | 2022-04-14 17:50:20 +0200 | [diff] [blame] | 480 | */ |
Thierry Fournier | 74a9eb5 | 2022-10-10 12:46:38 +0200 | [diff] [blame] | 481 | static int httpclient_spliturl(struct ist url, enum http_scheme *scheme, |
| 482 | struct ist *host, int *port) |
William Lallemand | 7f1df8f | 2022-04-14 17:50:20 +0200 | [diff] [blame] | 483 | { |
| 484 | enum http_scheme scheme_tmp = SCH_HTTP; |
| 485 | int port_tmp = 0; |
| 486 | struct ist scheme_ist, authority_ist, host_ist, port_ist; |
| 487 | char *p, *end; |
| 488 | struct http_uri_parser parser; |
| 489 | |
| 490 | parser = http_uri_parser_init(url); |
| 491 | scheme_ist = http_parse_scheme(&parser); |
Thierry Fournier | 74a9eb5 | 2022-10-10 12:46:38 +0200 | [diff] [blame] | 492 | if (!isttest(scheme_ist)) { |
| 493 | return 0; |
| 494 | } |
William Lallemand | 7f1df8f | 2022-04-14 17:50:20 +0200 | [diff] [blame] | 495 | |
| 496 | if (isteqi(scheme_ist, ist("http://"))){ |
| 497 | scheme_tmp = SCH_HTTP; |
| 498 | port_tmp = 80; |
| 499 | } else if (isteqi(scheme_ist, ist("https://"))) { |
| 500 | scheme_tmp = SCH_HTTPS; |
| 501 | port_tmp = 443; |
| 502 | } |
| 503 | |
| 504 | authority_ist = http_parse_authority(&parser, 1); |
Thierry Fournier | 74a9eb5 | 2022-10-10 12:46:38 +0200 | [diff] [blame] | 505 | if (!isttest(authority_ist)) { |
| 506 | return 0; |
| 507 | } |
William Lallemand | 7f1df8f | 2022-04-14 17:50:20 +0200 | [diff] [blame] | 508 | p = end = istend(authority_ist); |
| 509 | |
| 510 | /* look for a port at the end of the authority */ |
| 511 | while (p > istptr(authority_ist) && isdigit((unsigned char)*--p)) |
| 512 | ; |
| 513 | |
| 514 | if (*p == ':') { |
| 515 | host_ist = ist2(istptr(authority_ist), p - istptr(authority_ist)); |
| 516 | port_ist = istnext(ist2(p, end - p)); |
| 517 | ist2str(trash.area, port_ist); |
| 518 | port_tmp = atoi(trash.area); |
| 519 | } else { |
| 520 | host_ist = authority_ist; |
| 521 | } |
| 522 | |
| 523 | if (scheme) |
| 524 | *scheme = scheme_tmp; |
| 525 | if (host) |
| 526 | *host = host_ist; |
| 527 | if (port) |
| 528 | *port = port_tmp; |
| 529 | |
Thierry Fournier | 74a9eb5 | 2022-10-10 12:46:38 +0200 | [diff] [blame] | 530 | return 1; |
William Lallemand | 7f1df8f | 2022-04-14 17:50:20 +0200 | [diff] [blame] | 531 | } |
| 532 | |
| 533 | /* |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 534 | * Start the HTTP client |
| 535 | * Create the appctx, session, stream and wakeup the applet |
| 536 | * |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 537 | * Return the <appctx> or NULL if it failed |
| 538 | */ |
| 539 | struct appctx *httpclient_start(struct httpclient *hc) |
| 540 | { |
| 541 | struct applet *applet = &httpclient_applet; |
| 542 | struct appctx *appctx; |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 543 | |
William Lallemand | 5085bc3 | 2022-02-17 12:52:09 +0100 | [diff] [blame] | 544 | /* if the client was started and not ended, an applet is already |
| 545 | * running, we shouldn't try anything */ |
| 546 | if (httpclient_started(hc) && !httpclient_ended(hc)) |
| 547 | return NULL; |
| 548 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 549 | /* The HTTP client will be created in the same thread as the caller, |
| 550 | * avoiding threading issues */ |
Christopher Faulet | 6095d57 | 2022-05-16 17:09:48 +0200 | [diff] [blame] | 551 | appctx = appctx_new_here(applet, NULL); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 552 | if (!appctx) |
Christopher Faulet | a9e8b39 | 2022-03-23 11:01:09 +0100 | [diff] [blame] | 553 | goto out; |
Christopher Faulet | b1e0836 | 2022-05-12 15:33:14 +0200 | [diff] [blame] | 554 | appctx->svcctx = hc; |
| 555 | hc->flags = 0; |
William Lallemand | 7b2e0ee | 2022-02-17 19:10:55 +0100 | [diff] [blame] | 556 | |
Christopher Faulet | b1e0836 | 2022-05-12 15:33:14 +0200 | [diff] [blame] | 557 | if (appctx_init(appctx) == -1) { |
| 558 | ha_alert("httpclient: Failed to initialize appctx %s:%d.\n", __FUNCTION__, __LINE__); |
Christopher Faulet | 92202da | 2022-05-11 12:22:10 +0200 | [diff] [blame] | 559 | goto out_free_appctx; |
William Lallemand | 8533273 | 2022-05-04 10:59:51 +0200 | [diff] [blame] | 560 | } |
| 561 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 562 | return appctx; |
| 563 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 564 | out_free_appctx: |
Christopher Faulet | b1e0836 | 2022-05-12 15:33:14 +0200 | [diff] [blame] | 565 | appctx_free_on_early_error(appctx); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 566 | out: |
| 567 | |
| 568 | return NULL; |
| 569 | } |
| 570 | |
William Lallemand | ecb83e1 | 2021-09-28 11:00:43 +0200 | [diff] [blame] | 571 | /* |
| 572 | * This function tries to destroy the httpclient if it wasn't running. |
| 573 | * If it was running, stop the client and ask it to autodestroy itself. |
| 574 | * |
Ilya Shipitsin | bd6b4be | 2021-10-15 16:18:21 +0500 | [diff] [blame] | 575 | * Once this function is used, all pointer sto the client must be removed |
William Lallemand | ecb83e1 | 2021-09-28 11:00:43 +0200 | [diff] [blame] | 576 | * |
| 577 | */ |
| 578 | void httpclient_stop_and_destroy(struct httpclient *hc) |
| 579 | { |
| 580 | |
William Lallemand | b8b1370 | 2021-09-28 12:15:37 +0200 | [diff] [blame] | 581 | /* The httpclient was already stopped or never started, we can safely destroy it */ |
| 582 | if (hc->flags & HTTPCLIENT_FS_ENDED || !(hc->flags & HTTPCLIENT_FS_STARTED)) { |
William Lallemand | ecb83e1 | 2021-09-28 11:00:43 +0200 | [diff] [blame] | 583 | httpclient_destroy(hc); |
| 584 | } else { |
Willy Tarreau | b482920 | 2022-09-01 20:40:26 +0200 | [diff] [blame] | 585 | /* if the client wasn't stopped, ask for a stop and destroy */ |
William Lallemand | ecb83e1 | 2021-09-28 11:00:43 +0200 | [diff] [blame] | 586 | hc->flags |= (HTTPCLIENT_FA_AUTOKILL | HTTPCLIENT_FA_STOP); |
Willy Tarreau | b482920 | 2022-09-01 20:40:26 +0200 | [diff] [blame] | 587 | /* the calling applet doesn't exist anymore */ |
| 588 | hc->caller = NULL; |
William Lallemand | ecb83e1 | 2021-09-28 11:00:43 +0200 | [diff] [blame] | 589 | if (hc->appctx) |
| 590 | appctx_wakeup(hc->appctx); |
| 591 | } |
| 592 | } |
| 593 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 594 | /* Free the httpclient */ |
| 595 | void httpclient_destroy(struct httpclient *hc) |
| 596 | { |
William Lallemand | 03f5a1c | 2021-09-27 15:17:47 +0200 | [diff] [blame] | 597 | struct http_hdr *hdrs; |
| 598 | |
| 599 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 600 | if (!hc) |
| 601 | return; |
William Lallemand | ecb83e1 | 2021-09-28 11:00:43 +0200 | [diff] [blame] | 602 | |
William Lallemand | 2a87900 | 2021-10-05 15:50:45 +0200 | [diff] [blame] | 603 | /* we should never destroy a client which was started but not stopped */ |
| 604 | BUG_ON(httpclient_started(hc) && !httpclient_ended(hc)); |
William Lallemand | ecb83e1 | 2021-09-28 11:00:43 +0200 | [diff] [blame] | 605 | |
William Lallemand | 03f5a1c | 2021-09-27 15:17:47 +0200 | [diff] [blame] | 606 | /* request */ |
| 607 | istfree(&hc->req.url); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 608 | b_free(&hc->req.buf); |
William Lallemand | 03f5a1c | 2021-09-27 15:17:47 +0200 | [diff] [blame] | 609 | /* response */ |
| 610 | istfree(&hc->res.vsn); |
| 611 | istfree(&hc->res.reason); |
| 612 | hdrs = hc->res.hdrs; |
| 613 | while (hdrs && isttest(hdrs->n)) { |
| 614 | istfree(&hdrs->n); |
| 615 | istfree(&hdrs->v); |
| 616 | hdrs++; |
| 617 | } |
| 618 | ha_free(&hc->res.hdrs); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 619 | b_free(&hc->res.buf); |
William Lallemand | 7b2e0ee | 2022-02-17 19:10:55 +0100 | [diff] [blame] | 620 | sockaddr_free(&hc->dst); |
William Lallemand | 03f5a1c | 2021-09-27 15:17:47 +0200 | [diff] [blame] | 621 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 622 | free(hc); |
| 623 | |
| 624 | return; |
| 625 | } |
| 626 | |
| 627 | /* Allocate an httpclient and its buffers |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 628 | * Use the default httpclient_proxy |
| 629 | * |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 630 | * Return NULL on failure */ |
| 631 | struct httpclient *httpclient_new(void *caller, enum http_meth_t meth, struct ist url) |
| 632 | { |
| 633 | struct httpclient *hc; |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 634 | |
| 635 | hc = calloc(1, sizeof(*hc)); |
| 636 | if (!hc) |
| 637 | goto err; |
| 638 | |
Christopher Faulet | 600985d | 2022-01-12 11:14:08 +0100 | [diff] [blame] | 639 | hc->req.buf = BUF_NULL; |
| 640 | hc->res.buf = BUF_NULL; |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 641 | hc->caller = caller; |
William Lallemand | 67b7784 | 2021-11-10 16:57:25 +0100 | [diff] [blame] | 642 | hc->req.url = istdup(url); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 643 | hc->req.meth = meth; |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 644 | httpclient_set_proxy(hc, httpclient_proxy); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 645 | |
| 646 | return hc; |
| 647 | |
| 648 | err: |
| 649 | httpclient_destroy(hc); |
| 650 | return NULL; |
| 651 | } |
| 652 | |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 653 | /* Allocate an httpclient and its buffers, |
| 654 | * Use the proxy <px> |
| 655 | * |
| 656 | * Return and httpclient or NULL. |
| 657 | */ |
| 658 | struct httpclient *httpclient_new_from_proxy(struct proxy *px, void *caller, enum http_meth_t meth, struct ist url) |
| 659 | { |
| 660 | struct httpclient *hc; |
| 661 | |
| 662 | hc = httpclient_new(caller, meth, url); |
| 663 | if (!hc) |
| 664 | return NULL; |
| 665 | |
| 666 | httpclient_set_proxy(hc, px); |
| 667 | |
| 668 | return hc; |
| 669 | } |
| 670 | |
| 671 | /* |
| 672 | * Configure an httpclient with a specific proxy <px> |
| 673 | * |
| 674 | * The proxy <px> must contains 2 srv, one configured for clear connections, the other for SSL. |
| 675 | * |
| 676 | */ |
| 677 | int httpclient_set_proxy(struct httpclient *hc, struct proxy *px) |
| 678 | { |
| 679 | struct server *srv; |
| 680 | |
| 681 | hc->px = px; |
| 682 | |
| 683 | for (srv = px->srv; srv != NULL; srv = srv->next) { |
| 684 | if (srv->xprt == xprt_get(XPRT_RAW)) { |
| 685 | hc->srv_raw = srv; |
| 686 | #ifdef USE_OPENSSL |
| 687 | } else if (srv->xprt == xprt_get(XPRT_SSL)) { |
| 688 | hc->srv_ssl = srv; |
| 689 | #endif |
| 690 | } |
| 691 | } |
| 692 | |
| 693 | return 0; |
| 694 | } |
| 695 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 696 | static void httpclient_applet_io_handler(struct appctx *appctx) |
| 697 | { |
Willy Tarreau | 1eea665 | 2022-05-05 20:12:01 +0200 | [diff] [blame] | 698 | struct httpclient *hc = appctx->svcctx; |
Willy Tarreau | c12b321 | 2022-05-27 11:08:15 +0200 | [diff] [blame] | 699 | struct stconn *sc = appctx_sc(appctx); |
Willy Tarreau | b89f872 | 2022-05-27 10:37:32 +0200 | [diff] [blame] | 700 | struct stream *s = __sc_strm(sc); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 701 | struct channel *req = &s->req; |
| 702 | struct channel *res = &s->res; |
| 703 | struct htx_blk *blk = NULL; |
| 704 | struct htx *htx; |
William Lallemand | b702030 | 2021-08-20 11:24:13 +0200 | [diff] [blame] | 705 | struct htx_sl *sl = NULL; |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 706 | uint32_t hdr_num; |
William Lallemand | 2b7dc4e | 2022-02-24 16:55:41 +0100 | [diff] [blame] | 707 | uint32_t sz; |
William Lallemand | 933fe39 | 2021-11-04 09:45:58 +0100 | [diff] [blame] | 708 | int ret; |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 709 | |
William Lallemand | a93eac4 | 2022-10-20 18:36:03 +0200 | [diff] [blame^] | 710 | /* The IO handler could be called after the release, so we need to |
| 711 | * check if hc is still there to run the IO handler */ |
| 712 | if (!hc) |
| 713 | return; |
| 714 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 715 | while (1) { |
William Lallemand | ecb83e1 | 2021-09-28 11:00:43 +0200 | [diff] [blame] | 716 | |
| 717 | /* required to stop */ |
| 718 | if (hc->flags & HTTPCLIENT_FA_STOP) |
| 719 | goto end; |
| 720 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 721 | switch(appctx->st0) { |
| 722 | |
| 723 | case HTTPCLIENT_S_REQ: |
William Lallemand | db8a1f3 | 2021-11-08 16:55:14 +0100 | [diff] [blame] | 724 | /* we know that the buffer is empty here, since |
| 725 | * it's the first call, we can freely copy the |
| 726 | * request from the httpclient buffer */ |
William Lallemand | 933fe39 | 2021-11-04 09:45:58 +0100 | [diff] [blame] | 727 | ret = b_xfer(&req->buf, &hc->req.buf, b_data(&hc->req.buf)); |
William Lallemand | db8a1f3 | 2021-11-08 16:55:14 +0100 | [diff] [blame] | 728 | if (!ret) |
Willy Tarreau | 6486ff8 | 2022-09-02 11:42:50 +0200 | [diff] [blame] | 729 | goto full; |
William Lallemand | 933fe39 | 2021-11-04 09:45:58 +0100 | [diff] [blame] | 730 | |
Christopher Faulet | 600985d | 2022-01-12 11:14:08 +0100 | [diff] [blame] | 731 | if (!b_data(&hc->req.buf)) |
| 732 | b_free(&hc->req.buf); |
| 733 | |
William Lallemand | db8a1f3 | 2021-11-08 16:55:14 +0100 | [diff] [blame] | 734 | htx = htx_from_buf(&req->buf); |
William Lallemand | 933fe39 | 2021-11-04 09:45:58 +0100 | [diff] [blame] | 735 | if (!htx) |
Willy Tarreau | 6486ff8 | 2022-09-02 11:42:50 +0200 | [diff] [blame] | 736 | goto full; |
William Lallemand | 933fe39 | 2021-11-04 09:45:58 +0100 | [diff] [blame] | 737 | |
William Lallemand | db8a1f3 | 2021-11-08 16:55:14 +0100 | [diff] [blame] | 738 | channel_add_input(req, htx->data); |
| 739 | |
William Lallemand | 933fe39 | 2021-11-04 09:45:58 +0100 | [diff] [blame] | 740 | if (htx->flags & HTX_FL_EOM) /* check if a body need to be added */ |
| 741 | appctx->st0 = HTTPCLIENT_S_RES_STLINE; |
| 742 | else |
| 743 | appctx->st0 = HTTPCLIENT_S_REQ_BODY; |
| 744 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 745 | goto more; /* we need to leave the IO handler once we wrote the request */ |
| 746 | break; |
William Lallemand | 0da616e | 2021-10-28 15:34:26 +0200 | [diff] [blame] | 747 | case HTTPCLIENT_S_REQ_BODY: |
| 748 | /* call the payload callback */ |
| 749 | { |
| 750 | if (hc->ops.req_payload) { |
William Lallemand | ccc7ee4 | 2022-03-18 17:57:15 +0100 | [diff] [blame] | 751 | struct htx *hc_htx; |
William Lallemand | 0da616e | 2021-10-28 15:34:26 +0200 | [diff] [blame] | 752 | |
William Lallemand | 0da616e | 2021-10-28 15:34:26 +0200 | [diff] [blame] | 753 | /* call the request callback */ |
| 754 | hc->ops.req_payload(hc); |
William Lallemand | db8a1f3 | 2021-11-08 16:55:14 +0100 | [diff] [blame] | 755 | |
William Lallemand | ccc7ee4 | 2022-03-18 17:57:15 +0100 | [diff] [blame] | 756 | hc_htx = htx_from_buf(&hc->req.buf); |
William Lallemand | db8a1f3 | 2021-11-08 16:55:14 +0100 | [diff] [blame] | 757 | htx = htx_from_buf(&req->buf); |
William Lallemand | db8a1f3 | 2021-11-08 16:55:14 +0100 | [diff] [blame] | 758 | |
William Lallemand | ccc7ee4 | 2022-03-18 17:57:15 +0100 | [diff] [blame] | 759 | if (htx_is_empty(hc_htx)) |
William Lallemand | db8a1f3 | 2021-11-08 16:55:14 +0100 | [diff] [blame] | 760 | goto more; |
Christopher Faulet | 600985d | 2022-01-12 11:14:08 +0100 | [diff] [blame] | 761 | |
William Lallemand | ccc7ee4 | 2022-03-18 17:57:15 +0100 | [diff] [blame] | 762 | if (htx_is_empty(htx)) { |
Christopher Faulet | dca3b5b | 2022-04-07 10:47:07 +0200 | [diff] [blame] | 763 | size_t data = hc_htx->data; |
| 764 | |
William Lallemand | ccc7ee4 | 2022-03-18 17:57:15 +0100 | [diff] [blame] | 765 | /* Here htx_to_buf() will set buffer data to 0 because |
| 766 | * the HTX is empty, and allow us to do an xfer. |
| 767 | */ |
| 768 | htx_to_buf(hc_htx, &hc->req.buf); |
| 769 | htx_to_buf(htx, &req->buf); |
William Lallemand | ccc7ee4 | 2022-03-18 17:57:15 +0100 | [diff] [blame] | 770 | b_xfer(&req->buf, &hc->req.buf, b_data(&hc->req.buf)); |
Christopher Faulet | dca3b5b | 2022-04-07 10:47:07 +0200 | [diff] [blame] | 771 | channel_add_input(req, data); |
William Lallemand | ccc7ee4 | 2022-03-18 17:57:15 +0100 | [diff] [blame] | 772 | } else { |
| 773 | struct htx_ret ret; |
Christopher Faulet | 600985d | 2022-01-12 11:14:08 +0100 | [diff] [blame] | 774 | |
Christopher Faulet | 6b4f1f6 | 2022-04-29 13:56:12 +0200 | [diff] [blame] | 775 | ret = htx_xfer_blks(htx, hc_htx, htx_used_space(hc_htx), HTX_BLK_UNUSED); |
William Lallemand | ccc7ee4 | 2022-03-18 17:57:15 +0100 | [diff] [blame] | 776 | channel_add_input(req, ret.ret); |
William Lallemand | db8a1f3 | 2021-11-08 16:55:14 +0100 | [diff] [blame] | 777 | |
William Lallemand | ccc7ee4 | 2022-03-18 17:57:15 +0100 | [diff] [blame] | 778 | /* we must copy the EOM if we empty the buffer */ |
| 779 | if (htx_is_empty(hc_htx)) { |
| 780 | htx->flags |= (hc_htx->flags & HTX_FL_EOM); |
| 781 | } |
| 782 | htx_to_buf(htx, &req->buf); |
| 783 | htx_to_buf(hc_htx, &hc->req.buf); |
| 784 | } |
| 785 | |
| 786 | |
| 787 | if (!b_data(&hc->req.buf)) |
| 788 | b_free(&hc->req.buf); |
William Lallemand | 0da616e | 2021-10-28 15:34:26 +0200 | [diff] [blame] | 789 | } |
| 790 | |
William Lallemand | db8a1f3 | 2021-11-08 16:55:14 +0100 | [diff] [blame] | 791 | htx = htx_from_buf(&req->buf); |
William Lallemand | 0da616e | 2021-10-28 15:34:26 +0200 | [diff] [blame] | 792 | if (!htx) |
| 793 | goto more; |
| 794 | |
| 795 | /* if the request contains the HTX_FL_EOM, we finished the request part. */ |
Christopher Faulet | 3d43324 | 2022-03-03 15:38:39 +0100 | [diff] [blame] | 796 | if (htx->flags & HTX_FL_EOM) { |
Christopher Faulet | 3d43324 | 2022-03-03 15:38:39 +0100 | [diff] [blame] | 797 | req->flags |= CF_EOI; |
Willy Tarreau | d869e13 | 2022-05-17 18:05:31 +0200 | [diff] [blame] | 798 | se_fl_set(appctx->sedesc, SE_FL_EOI); |
William Lallemand | 0da616e | 2021-10-28 15:34:26 +0200 | [diff] [blame] | 799 | appctx->st0 = HTTPCLIENT_S_RES_STLINE; |
Christopher Faulet | 3d43324 | 2022-03-03 15:38:39 +0100 | [diff] [blame] | 800 | } |
William Lallemand | 0da616e | 2021-10-28 15:34:26 +0200 | [diff] [blame] | 801 | |
William Lallemand | 1eca894 | 2022-03-17 14:57:23 +0100 | [diff] [blame] | 802 | goto process_data; /* we need to leave the IO handler once we wrote the request */ |
William Lallemand | 0da616e | 2021-10-28 15:34:26 +0200 | [diff] [blame] | 803 | } |
| 804 | break; |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 805 | |
| 806 | case HTTPCLIENT_S_RES_STLINE: |
| 807 | /* copy the start line in the hc structure,then remove the htx block */ |
William Lallemand | a625b03 | 2022-03-17 14:45:46 +0100 | [diff] [blame] | 808 | if (!co_data(res)) |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 809 | goto more; |
| 810 | htx = htxbuf(&res->buf); |
| 811 | if (!htx) |
| 812 | goto more; |
William Lallemand | 97f69c6 | 2022-03-10 17:23:40 +0100 | [diff] [blame] | 813 | blk = htx_get_head_blk(htx); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 814 | if (blk && (htx_get_blk_type(blk) == HTX_BLK_RES_SL)) |
| 815 | sl = htx_get_blk_ptr(htx, blk); |
| 816 | if (!sl || (!(sl->flags & HTX_SL_F_IS_RESP))) |
| 817 | goto more; |
| 818 | |
| 819 | /* copy the status line in the httpclient */ |
| 820 | hc->res.status = sl->info.res.status; |
| 821 | hc->res.vsn = istdup(htx_sl_res_vsn(sl)); |
| 822 | hc->res.reason = istdup(htx_sl_res_reason(sl)); |
William Lallemand | 2b7dc4e | 2022-02-24 16:55:41 +0100 | [diff] [blame] | 823 | sz = htx_get_blksz(blk); |
Christopher Faulet | 0055d56 | 2022-04-29 14:09:03 +0200 | [diff] [blame] | 824 | c_rew(res, sz); |
William Lallemand | 2b7dc4e | 2022-02-24 16:55:41 +0100 | [diff] [blame] | 825 | htx_remove_blk(htx, blk); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 826 | /* caller callback */ |
| 827 | if (hc->ops.res_stline) |
| 828 | hc->ops.res_stline(hc); |
| 829 | |
| 830 | /* if there is no HTX data anymore and the EOM flag is |
| 831 | * set, leave (no body) */ |
| 832 | if (htx_is_empty(htx) && htx->flags & HTX_FL_EOM) |
| 833 | appctx->st0 = HTTPCLIENT_S_RES_END; |
| 834 | else |
| 835 | appctx->st0 = HTTPCLIENT_S_RES_HDR; |
| 836 | break; |
| 837 | |
| 838 | case HTTPCLIENT_S_RES_HDR: |
| 839 | /* first copy the headers in a local hdrs |
| 840 | * structure, once we the total numbers of the |
| 841 | * header we allocate the right size and copy |
| 842 | * them. The htx block of the headers are |
| 843 | * removed each time one is read */ |
| 844 | { |
| 845 | struct http_hdr hdrs[global.tune.max_http_hdr]; |
| 846 | |
William Lallemand | a625b03 | 2022-03-17 14:45:46 +0100 | [diff] [blame] | 847 | if (!co_data(res)) |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 848 | goto more; |
| 849 | htx = htxbuf(&res->buf); |
| 850 | if (!htx) |
| 851 | goto more; |
| 852 | |
| 853 | hdr_num = 0; |
Christopher Faulet | 534645d | 2022-04-29 13:44:46 +0200 | [diff] [blame] | 854 | blk = htx_get_head_blk(htx); |
| 855 | while (blk) { |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 856 | enum htx_blk_type type = htx_get_blk_type(blk); |
William Lallemand | 2b7dc4e | 2022-02-24 16:55:41 +0100 | [diff] [blame] | 857 | uint32_t sz = htx_get_blksz(blk); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 858 | |
Christopher Faulet | 534645d | 2022-04-29 13:44:46 +0200 | [diff] [blame] | 859 | c_rew(res, sz); |
William Lallemand | c020b25 | 2022-03-09 18:56:02 +0100 | [diff] [blame] | 860 | |
Christopher Faulet | 18de6f2 | 2022-06-01 16:37:49 +0200 | [diff] [blame] | 861 | if (type == HTX_BLK_HDR) { |
William Lallemand | c020b25 | 2022-03-09 18:56:02 +0100 | [diff] [blame] | 862 | hdrs[hdr_num].n = istdup(htx_get_blk_name(htx, blk)); |
| 863 | hdrs[hdr_num].v = istdup(htx_get_blk_value(htx, blk)); |
William Lallemand | c020b25 | 2022-03-09 18:56:02 +0100 | [diff] [blame] | 864 | hdr_num++; |
| 865 | } |
Christopher Faulet | 534645d | 2022-04-29 13:44:46 +0200 | [diff] [blame] | 866 | else if (type == HTX_BLK_EOH) { |
| 867 | /* create a NULL end of array and leave the loop */ |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 868 | hdrs[hdr_num].n = IST_NULL; |
| 869 | hdrs[hdr_num].v = IST_NULL; |
Christopher Faulet | 18de6f2 | 2022-06-01 16:37:49 +0200 | [diff] [blame] | 870 | htx_remove_blk(htx, blk); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 871 | break; |
| 872 | } |
Christopher Faulet | 18de6f2 | 2022-06-01 16:37:49 +0200 | [diff] [blame] | 873 | blk = htx_remove_blk(htx, blk); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 874 | } |
| 875 | |
William Lallemand | 0d6f779 | 2021-08-20 11:59:49 +0200 | [diff] [blame] | 876 | if (hdr_num) { |
| 877 | /* alloc and copy the headers in the httpclient struct */ |
| 878 | hc->res.hdrs = calloc((hdr_num + 1), sizeof(*hc->res.hdrs)); |
| 879 | if (!hc->res.hdrs) |
| 880 | goto end; |
| 881 | memcpy(hc->res.hdrs, hdrs, sizeof(struct http_hdr) * (hdr_num + 1)); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 882 | |
William Lallemand | 0d6f779 | 2021-08-20 11:59:49 +0200 | [diff] [blame] | 883 | /* caller callback */ |
| 884 | if (hc->ops.res_headers) |
| 885 | hc->ops.res_headers(hc); |
| 886 | } |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 887 | |
| 888 | /* if there is no HTX data anymore and the EOM flag is |
| 889 | * set, leave (no body) */ |
William Lallemand | 1123dde | 2021-09-21 10:58:10 +0200 | [diff] [blame] | 890 | if (htx_is_empty(htx) && htx->flags & HTX_FL_EOM) { |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 891 | appctx->st0 = HTTPCLIENT_S_RES_END; |
William Lallemand | 1123dde | 2021-09-21 10:58:10 +0200 | [diff] [blame] | 892 | } else { |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 893 | appctx->st0 = HTTPCLIENT_S_RES_BODY; |
William Lallemand | 1123dde | 2021-09-21 10:58:10 +0200 | [diff] [blame] | 894 | } |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 895 | } |
| 896 | break; |
| 897 | |
| 898 | case HTTPCLIENT_S_RES_BODY: |
| 899 | /* |
| 900 | * The IO handler removes the htx blocks in the response buffer and |
| 901 | * push them in the hc->res.buf buffer in a raw format. |
| 902 | */ |
William Lallemand | a625b03 | 2022-03-17 14:45:46 +0100 | [diff] [blame] | 903 | if (!co_data(res)) |
William Lallemand | 2b7dc4e | 2022-02-24 16:55:41 +0100 | [diff] [blame] | 904 | goto more; |
| 905 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 906 | htx = htxbuf(&res->buf); |
| 907 | if (!htx || htx_is_empty(htx)) |
| 908 | goto more; |
| 909 | |
Christopher Faulet | 600985d | 2022-01-12 11:14:08 +0100 | [diff] [blame] | 910 | if (!b_alloc(&hc->res.buf)) |
| 911 | goto more; |
| 912 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 913 | if (b_full(&hc->res.buf)) |
Christopher Faulet | 600985d | 2022-01-12 11:14:08 +0100 | [diff] [blame] | 914 | goto process_data; |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 915 | |
| 916 | /* decapsule the htx data to raw data */ |
Christopher Faulet | 534645d | 2022-04-29 13:44:46 +0200 | [diff] [blame] | 917 | blk = htx_get_head_blk(htx); |
| 918 | while (blk) { |
William Lallemand | c8f1eb9 | 2022-03-09 11:58:51 +0100 | [diff] [blame] | 919 | enum htx_blk_type type = htx_get_blk_type(blk); |
| 920 | size_t count = co_data(res); |
| 921 | uint32_t blksz = htx_get_blksz(blk); |
| 922 | uint32_t room = b_room(&hc->res.buf); |
| 923 | uint32_t vlen; |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 924 | |
William Lallemand | c8f1eb9 | 2022-03-09 11:58:51 +0100 | [diff] [blame] | 925 | /* we should try to copy the maximum output data in a block, which fit |
| 926 | * the destination buffer */ |
| 927 | vlen = MIN(count, blksz); |
| 928 | vlen = MIN(vlen, room); |
William Lallemand | 2b7dc4e | 2022-02-24 16:55:41 +0100 | [diff] [blame] | 929 | |
William Lallemand | c8f1eb9 | 2022-03-09 11:58:51 +0100 | [diff] [blame] | 930 | if (vlen == 0) |
William Lallemand | 2b7dc4e | 2022-02-24 16:55:41 +0100 | [diff] [blame] | 931 | goto process_data; |
| 932 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 933 | if (type == HTX_BLK_DATA) { |
| 934 | struct ist v = htx_get_blk_value(htx, blk); |
| 935 | |
William Lallemand | c8f1eb9 | 2022-03-09 11:58:51 +0100 | [diff] [blame] | 936 | __b_putblk(&hc->res.buf, v.ptr, vlen); |
| 937 | c_rew(res, vlen); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 938 | |
William Lallemand | c8f1eb9 | 2022-03-09 11:58:51 +0100 | [diff] [blame] | 939 | if (vlen == blksz) |
Christopher Faulet | 534645d | 2022-04-29 13:44:46 +0200 | [diff] [blame] | 940 | blk = htx_remove_blk(htx, blk); |
William Lallemand | c8f1eb9 | 2022-03-09 11:58:51 +0100 | [diff] [blame] | 941 | else |
| 942 | htx_cut_data_blk(htx, blk, vlen); |
William Lallemand | 2b7dc4e | 2022-02-24 16:55:41 +0100 | [diff] [blame] | 943 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 944 | /* the data must be processed by the caller in the receive phase */ |
| 945 | if (hc->ops.res_payload) |
| 946 | hc->ops.res_payload(hc); |
William Lallemand | c8f1eb9 | 2022-03-09 11:58:51 +0100 | [diff] [blame] | 947 | |
Ilya Shipitsin | 3b64a28 | 2022-07-29 22:26:53 +0500 | [diff] [blame] | 948 | /* cannot copy everything, need to process */ |
William Lallemand | c8f1eb9 | 2022-03-09 11:58:51 +0100 | [diff] [blame] | 949 | if (vlen != blksz) |
| 950 | goto process_data; |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 951 | } else { |
William Lallemand | c8f1eb9 | 2022-03-09 11:58:51 +0100 | [diff] [blame] | 952 | if (vlen != blksz) |
| 953 | goto process_data; |
| 954 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 955 | /* remove any block which is not a data block */ |
William Lallemand | c8f1eb9 | 2022-03-09 11:58:51 +0100 | [diff] [blame] | 956 | c_rew(res, blksz); |
Christopher Faulet | 534645d | 2022-04-29 13:44:46 +0200 | [diff] [blame] | 957 | blk = htx_remove_blk(htx, blk); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 958 | } |
| 959 | } |
William Lallemand | c8f1eb9 | 2022-03-09 11:58:51 +0100 | [diff] [blame] | 960 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 961 | /* if not finished, should be called again */ |
William Lallemand | c8f1eb9 | 2022-03-09 11:58:51 +0100 | [diff] [blame] | 962 | if (!(htx_is_empty(htx) && (htx->flags & HTX_FL_EOM))) |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 963 | goto more; |
| 964 | |
William Lallemand | c8f1eb9 | 2022-03-09 11:58:51 +0100 | [diff] [blame] | 965 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 966 | /* end of message, we should quit */ |
| 967 | appctx->st0 = HTTPCLIENT_S_RES_END; |
| 968 | break; |
| 969 | |
| 970 | case HTTPCLIENT_S_RES_END: |
| 971 | goto end; |
| 972 | break; |
| 973 | } |
| 974 | } |
| 975 | |
| 976 | process_data: |
| 977 | |
Willy Tarreau | b89f872 | 2022-05-27 10:37:32 +0200 | [diff] [blame] | 978 | sc_will_read(sc); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 979 | |
| 980 | return; |
Willy Tarreau | 6486ff8 | 2022-09-02 11:42:50 +0200 | [diff] [blame] | 981 | full: |
| 982 | /* There was not enough room in the response channel */ |
Willy Tarreau | b89f872 | 2022-05-27 10:37:32 +0200 | [diff] [blame] | 983 | sc_need_room(sc); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 984 | |
Willy Tarreau | 6486ff8 | 2022-09-02 11:42:50 +0200 | [diff] [blame] | 985 | more: |
| 986 | /* we'll automatically be called again on missing data */ |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 987 | if (appctx->st0 == HTTPCLIENT_S_RES_END) |
| 988 | goto end; |
| 989 | |
| 990 | /* The state machine tries to handle as much data as possible, if there |
| 991 | * isn't any data to handle and a shutdown is detected, let's stop |
| 992 | * everything */ |
| 993 | if ((req->flags & (CF_SHUTR|CF_SHUTR_NOW)) || |
William Lallemand | 58a81ae | 2022-03-17 15:14:15 +0100 | [diff] [blame] | 994 | (res->flags & CF_SHUTW) || |
| 995 | ((res->flags & CF_SHUTW_NOW) && channel_is_empty(res))) { |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 996 | goto end; |
| 997 | } |
| 998 | return; |
| 999 | |
| 1000 | end: |
Willy Tarreau | b89f872 | 2022-05-27 10:37:32 +0200 | [diff] [blame] | 1001 | sc_shutw(sc); |
| 1002 | sc_shutr(sc); |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 1003 | return; |
| 1004 | } |
| 1005 | |
Christopher Faulet | b1e0836 | 2022-05-12 15:33:14 +0200 | [diff] [blame] | 1006 | static int httpclient_applet_init(struct appctx *appctx) |
| 1007 | { |
| 1008 | struct httpclient *hc = appctx->svcctx; |
| 1009 | struct stream *s; |
| 1010 | struct sockaddr_storage *addr = NULL; |
| 1011 | struct sockaddr_storage ss_url = {}; |
| 1012 | struct sockaddr_storage *ss_dst; |
| 1013 | enum obj_type *target = NULL; |
| 1014 | struct ist host = IST_NULL; |
| 1015 | enum http_scheme scheme; |
| 1016 | int port; |
| 1017 | int doresolve = 0; |
| 1018 | |
| 1019 | |
| 1020 | /* parse the URL and */ |
Thierry Fournier | 74a9eb5 | 2022-10-10 12:46:38 +0200 | [diff] [blame] | 1021 | if (!httpclient_spliturl(hc->req.url, &scheme, &host, &port)) |
| 1022 | goto out_error; |
Christopher Faulet | b1e0836 | 2022-05-12 15:33:14 +0200 | [diff] [blame] | 1023 | |
| 1024 | if (hc->dst) { |
| 1025 | /* if httpclient_set_dst() was used, sets the alternative address */ |
| 1026 | ss_dst = hc->dst; |
| 1027 | } else { |
| 1028 | /* set the dst using the host, or 0.0.0.0 to resolve */ |
| 1029 | ist2str(trash.area, host); |
| 1030 | ss_dst = str2ip2(trash.area, &ss_url, 0); |
| 1031 | if (!ss_dst) { /* couldn't get an IP from that, try to resolve */ |
| 1032 | doresolve = 1; |
| 1033 | ss_dst = str2ip2("0.0.0.0", &ss_url, 0); |
| 1034 | } |
| 1035 | sock_inet_set_port(ss_dst, port); |
| 1036 | } |
| 1037 | |
Christopher Faulet | b1e0836 | 2022-05-12 15:33:14 +0200 | [diff] [blame] | 1038 | if (!sockaddr_alloc(&addr, ss_dst, sizeof(*ss_dst))) |
| 1039 | goto out_error; |
| 1040 | |
| 1041 | /* choose the SSL server or not */ |
| 1042 | switch (scheme) { |
| 1043 | case SCH_HTTP: |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 1044 | target = &hc->srv_raw->obj_type; |
Christopher Faulet | b1e0836 | 2022-05-12 15:33:14 +0200 | [diff] [blame] | 1045 | break; |
| 1046 | case SCH_HTTPS: |
| 1047 | #ifdef USE_OPENSSL |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 1048 | if (hc->srv_ssl) { |
| 1049 | target = &hc->srv_ssl->obj_type; |
Christopher Faulet | b1e0836 | 2022-05-12 15:33:14 +0200 | [diff] [blame] | 1050 | } else { |
| 1051 | ha_alert("httpclient: SSL was disabled (wrong verify/ca-file)!\n"); |
| 1052 | goto out_free_addr; |
| 1053 | } |
| 1054 | #else |
| 1055 | ha_alert("httpclient: OpenSSL is not available %s:%d.\n", __FUNCTION__, __LINE__); |
| 1056 | goto out_free_addr; |
| 1057 | #endif |
| 1058 | break; |
| 1059 | } |
| 1060 | |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 1061 | if (appctx_finalize_startup(appctx, hc->px, &hc->req.buf) == -1) { |
Christopher Faulet | b1e0836 | 2022-05-12 15:33:14 +0200 | [diff] [blame] | 1062 | ha_alert("httpclient: Failed to initialize appctx %s:%d.\n", __FUNCTION__, __LINE__); |
| 1063 | goto out_free_addr; |
| 1064 | } |
| 1065 | |
| 1066 | s = appctx_strm(appctx); |
| 1067 | s->target = target; |
| 1068 | /* set the "timeout server" */ |
| 1069 | s->req.wto = hc->timeout_server; |
| 1070 | s->res.rto = hc->timeout_server; |
| 1071 | |
| 1072 | if (doresolve) { |
| 1073 | /* in order to do the set-dst we need to put the address on the front */ |
Willy Tarreau | 7cb9e6c | 2022-05-17 19:40:40 +0200 | [diff] [blame] | 1074 | s->scf->dst = addr; |
Christopher Faulet | b1e0836 | 2022-05-12 15:33:14 +0200 | [diff] [blame] | 1075 | } else { |
| 1076 | /* in cases we don't use the resolve we already have the address |
| 1077 | * and must put it on the backend side, some of the cases are |
| 1078 | * not meant to be used on the frontend (sockpair, unix socket etc.) */ |
Willy Tarreau | 7cb9e6c | 2022-05-17 19:40:40 +0200 | [diff] [blame] | 1079 | s->scb->dst = addr; |
Christopher Faulet | b1e0836 | 2022-05-12 15:33:14 +0200 | [diff] [blame] | 1080 | } |
| 1081 | |
Willy Tarreau | cb04166 | 2022-05-17 19:44:42 +0200 | [diff] [blame] | 1082 | s->scb->flags |= SC_FL_NOLINGER; |
Christopher Faulet | b1e0836 | 2022-05-12 15:33:14 +0200 | [diff] [blame] | 1083 | s->flags |= SF_ASSIGNED; |
| 1084 | s->res.flags |= CF_READ_DONTWAIT; |
| 1085 | |
| 1086 | /* applet is waiting for data */ |
Willy Tarreau | 90e8b45 | 2022-05-25 18:21:43 +0200 | [diff] [blame] | 1087 | applet_need_more_data(appctx); |
Christopher Faulet | b1e0836 | 2022-05-12 15:33:14 +0200 | [diff] [blame] | 1088 | appctx_wakeup(appctx); |
| 1089 | |
| 1090 | hc->appctx = appctx; |
| 1091 | hc->flags |= HTTPCLIENT_FS_STARTED; |
| 1092 | |
| 1093 | /* The request was transferred when the stream was created. So switch |
| 1094 | * directly to REQ_BODY or RES_STLINE state |
| 1095 | */ |
| 1096 | appctx->st0 = (hc->ops.req_payload ? HTTPCLIENT_S_REQ_BODY : HTTPCLIENT_S_RES_STLINE); |
| 1097 | return 0; |
| 1098 | |
| 1099 | out_free_addr: |
| 1100 | sockaddr_free(&addr); |
| 1101 | out_error: |
| 1102 | return -1; |
| 1103 | } |
| 1104 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 1105 | static void httpclient_applet_release(struct appctx *appctx) |
| 1106 | { |
Willy Tarreau | 1eea665 | 2022-05-05 20:12:01 +0200 | [diff] [blame] | 1107 | struct httpclient *hc = appctx->svcctx; |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 1108 | |
William Lallemand | 1123dde | 2021-09-21 10:58:10 +0200 | [diff] [blame] | 1109 | /* mark the httpclient as ended */ |
William Lallemand | ecb83e1 | 2021-09-28 11:00:43 +0200 | [diff] [blame] | 1110 | hc->flags |= HTTPCLIENT_FS_ENDED; |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 1111 | /* the applet is leaving, remove the ptr so we don't try to call it |
| 1112 | * again from the caller */ |
| 1113 | hc->appctx = NULL; |
| 1114 | |
William Lallemand | eb0d4c4 | 2022-04-06 14:12:37 +0200 | [diff] [blame] | 1115 | if (hc->ops.res_end) |
| 1116 | hc->ops.res_end(hc); |
William Lallemand | ecb83e1 | 2021-09-28 11:00:43 +0200 | [diff] [blame] | 1117 | |
| 1118 | /* destroy the httpclient when set to autotokill */ |
| 1119 | if (hc->flags & HTTPCLIENT_FA_AUTOKILL) { |
| 1120 | httpclient_destroy(hc); |
| 1121 | } |
| 1122 | |
William Lallemand | a93eac4 | 2022-10-20 18:36:03 +0200 | [diff] [blame^] | 1123 | /* be sure not to use this ptr anymore if the IO handler is called a |
| 1124 | * last time */ |
| 1125 | appctx->svcctx = NULL; |
| 1126 | |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 1127 | return; |
| 1128 | } |
| 1129 | |
| 1130 | /* HTTP client applet */ |
| 1131 | static struct applet httpclient_applet = { |
| 1132 | .obj_type = OBJ_TYPE_APPLET, |
| 1133 | .name = "<HTTPCLIENT>", |
| 1134 | .fct = httpclient_applet_io_handler, |
Christopher Faulet | b1e0836 | 2022-05-12 15:33:14 +0200 | [diff] [blame] | 1135 | .init = httpclient_applet_init, |
William Lallemand | 33b0d09 | 2021-08-13 16:05:53 +0200 | [diff] [blame] | 1136 | .release = httpclient_applet_release, |
| 1137 | }; |
| 1138 | |
William Lallemand | 5392ff6 | 2022-04-28 16:55:02 +0200 | [diff] [blame] | 1139 | |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1140 | static int httpclient_resolve_init(struct proxy *px) |
William Lallemand | 5392ff6 | 2022-04-28 16:55:02 +0200 | [diff] [blame] | 1141 | { |
| 1142 | struct act_rule *rule; |
| 1143 | int i; |
William Lallemand | 8a734cb | 2022-05-04 16:10:47 +0200 | [diff] [blame] | 1144 | char *do_resolve = NULL; |
| 1145 | char *http_rules[][11] = { |
William Lallemand | 5392ff6 | 2022-04-28 16:55:02 +0200 | [diff] [blame] | 1146 | { "set-var(txn.hc_ip)", "dst", "" }, |
William Lallemand | d78dfe7 | 2022-08-26 16:45:13 +0200 | [diff] [blame] | 1147 | { do_resolve, "hdr(Host),host_only", "if", "{", "var(txn.hc_ip)", "-m", "ip", "0.0.0.0", "}", "" }, |
William Lallemand | 5392ff6 | 2022-04-28 16:55:02 +0200 | [diff] [blame] | 1148 | { "return", "status", "503", "if", "{", "var(txn.hc_ip)", "-m", "ip", "0.0.0.0", "}", "" }, |
| 1149 | { "capture", "var(txn.hc_ip)", "len", "40", "" }, |
| 1150 | { "set-dst", "var(txn.hc_ip)", "" }, |
| 1151 | { "" } |
| 1152 | }; |
| 1153 | |
William Lallemand | 8a734cb | 2022-05-04 16:10:47 +0200 | [diff] [blame] | 1154 | if (!resolvers_id) |
| 1155 | resolvers_id = strdup("default"); |
| 1156 | |
William Lallemand | 7c5a7ef | 2022-05-04 15:59:44 +0200 | [diff] [blame] | 1157 | memprintf(&do_resolve, "do-resolve(txn.hc_ip,%s%s%s)", resolvers_id, resolvers_prefer ? "," : "", resolvers_prefer ? resolvers_prefer : ""); |
William Lallemand | 8a734cb | 2022-05-04 16:10:47 +0200 | [diff] [blame] | 1158 | http_rules[1][0] = do_resolve; |
| 1159 | |
William Lallemand | 7867f63 | 2022-05-05 19:02:59 +0200 | [diff] [blame] | 1160 | /* Try to create the default resolvers section */ |
| 1161 | resolvers_create_default(); |
| 1162 | |
William Lallemand | 8a734cb | 2022-05-04 16:10:47 +0200 | [diff] [blame] | 1163 | /* if the resolver does not exist and no hard_error was set, simply ignore resolving */ |
| 1164 | if (!find_resolvers_by_id(resolvers_id) && !hard_error_resolvers) { |
| 1165 | free(do_resolve); |
William Lallemand | 5392ff6 | 2022-04-28 16:55:02 +0200 | [diff] [blame] | 1166 | return 0; |
William Lallemand | 8a734cb | 2022-05-04 16:10:47 +0200 | [diff] [blame] | 1167 | } |
William Lallemand | 5392ff6 | 2022-04-28 16:55:02 +0200 | [diff] [blame] | 1168 | |
| 1169 | |
| 1170 | for (i = 0; *http_rules[i][0] != '\0'; i++) { |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1171 | rule = parse_http_req_cond((const char **)http_rules[i], "httpclient", 0, px); |
William Lallemand | 5392ff6 | 2022-04-28 16:55:02 +0200 | [diff] [blame] | 1172 | if (!rule) { |
William Lallemand | 8a734cb | 2022-05-04 16:10:47 +0200 | [diff] [blame] | 1173 | free(do_resolve); |
William Lallemand | 5392ff6 | 2022-04-28 16:55:02 +0200 | [diff] [blame] | 1174 | ha_alert("Couldn't setup the httpclient resolver.\n"); |
| 1175 | return 1; |
| 1176 | } |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1177 | LIST_APPEND(&px->http_req_rules, &rule->list); |
William Lallemand | 5392ff6 | 2022-04-28 16:55:02 +0200 | [diff] [blame] | 1178 | } |
| 1179 | |
William Lallemand | 8a734cb | 2022-05-04 16:10:47 +0200 | [diff] [blame] | 1180 | free(do_resolve); |
William Lallemand | 5392ff6 | 2022-04-28 16:55:02 +0200 | [diff] [blame] | 1181 | return 0; |
| 1182 | } |
| 1183 | |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1184 | /* |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1185 | * Creates an internal proxy which will be used for httpclient. |
| 1186 | * This will allocate 2 servers (raw and ssl) and 1 proxy. |
| 1187 | * |
| 1188 | * This function must be called from a precheck callback. |
| 1189 | * |
| 1190 | * Return a proxy or NULL. |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1191 | */ |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1192 | struct proxy *httpclient_create_proxy(const char *id) |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1193 | { |
William Lallemand | 85af49c | 2022-05-04 14:33:57 +0200 | [diff] [blame] | 1194 | int err_code = ERR_NONE; |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1195 | char *errmsg = NULL; |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1196 | struct proxy *px = NULL; |
| 1197 | struct server *srv_raw = NULL; |
| 1198 | #ifdef USE_OPENSSL |
| 1199 | struct server *srv_ssl = NULL; |
| 1200 | #endif |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1201 | |
William Lallemand | c6ceba3 | 2022-04-22 16:49:53 +0200 | [diff] [blame] | 1202 | if (global.mode & MODE_MWORKER_WAIT) |
William Lallemand | 85af49c | 2022-05-04 14:33:57 +0200 | [diff] [blame] | 1203 | return ERR_NONE; |
William Lallemand | c6ceba3 | 2022-04-22 16:49:53 +0200 | [diff] [blame] | 1204 | |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1205 | px = alloc_new_proxy(id, PR_CAP_LISTEN|PR_CAP_INT|PR_CAP_HTTPCLIENT, &errmsg); |
| 1206 | if (!px) { |
William Lallemand | 85af49c | 2022-05-04 14:33:57 +0200 | [diff] [blame] | 1207 | memprintf(&errmsg, "couldn't allocate proxy."); |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1208 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1209 | goto err; |
| 1210 | } |
| 1211 | |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1212 | proxy_preset_defaults(px); |
Willy Tarreau | 0e72e40 | 2021-08-20 10:23:12 +0200 | [diff] [blame] | 1213 | |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1214 | px->options |= PR_O_WREQ_BODY; |
| 1215 | px->retry_type |= PR_RE_CONN_FAILED | PR_RE_DISCONNECTED | PR_RE_TIMEOUT; |
| 1216 | px->options2 |= PR_O2_INDEPSTR; |
| 1217 | px->mode = PR_MODE_HTTP; |
| 1218 | px->maxconn = 0; |
| 1219 | px->accept = NULL; |
| 1220 | px->conn_retries = CONN_RETRIES; |
| 1221 | px->timeout.client = TICK_ETERNITY; |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1222 | /* The HTTP Client use the "option httplog" with the global log server */ |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1223 | px->conf.logformat_string = default_http_log_format; |
| 1224 | px->http_needed = 1; |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1225 | |
| 1226 | /* clear HTTP server */ |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1227 | srv_raw = new_server(px); |
| 1228 | if (!srv_raw) { |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1229 | memprintf(&errmsg, "out of memory."); |
William Lallemand | 85af49c | 2022-05-04 14:33:57 +0200 | [diff] [blame] | 1230 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1231 | goto err; |
| 1232 | } |
| 1233 | |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1234 | srv_settings_cpy(srv_raw, &px->defsrv, 0); |
| 1235 | srv_raw->iweight = 0; |
| 1236 | srv_raw->uweight = 0; |
| 1237 | srv_raw->xprt = xprt_get(XPRT_RAW); |
| 1238 | srv_raw->flags |= SRV_F_MAPPORTS; /* needed to apply the port change with resolving */ |
| 1239 | srv_raw->id = strdup("<HTTPCLIENT>"); |
| 1240 | if (!srv_raw->id) { |
William Lallemand | 85af49c | 2022-05-04 14:33:57 +0200 | [diff] [blame] | 1241 | memprintf(&errmsg, "out of memory."); |
| 1242 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1243 | goto err; |
William Lallemand | 85af49c | 2022-05-04 14:33:57 +0200 | [diff] [blame] | 1244 | } |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1245 | |
William Lallemand | 957ab13 | 2021-08-24 18:33:28 +0200 | [diff] [blame] | 1246 | #ifdef USE_OPENSSL |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1247 | /* SSL HTTP server */ |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1248 | srv_ssl = new_server(px); |
| 1249 | if (!srv_ssl) { |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1250 | memprintf(&errmsg, "out of memory."); |
| 1251 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1252 | goto err; |
| 1253 | } |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1254 | srv_settings_cpy(srv_ssl, &px->defsrv, 0); |
| 1255 | srv_ssl->iweight = 0; |
| 1256 | srv_ssl->uweight = 0; |
| 1257 | srv_ssl->xprt = xprt_get(XPRT_SSL); |
| 1258 | srv_ssl->use_ssl = 1; |
| 1259 | srv_ssl->flags |= SRV_F_MAPPORTS; /* needed to apply the port change with resolving */ |
| 1260 | srv_ssl->id = strdup("<HTTPSCLIENT>"); |
| 1261 | if (!srv_ssl->id) { |
William Lallemand | 85af49c | 2022-05-04 14:33:57 +0200 | [diff] [blame] | 1262 | memprintf(&errmsg, "out of memory."); |
| 1263 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1264 | goto err; |
William Lallemand | 85af49c | 2022-05-04 14:33:57 +0200 | [diff] [blame] | 1265 | } |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1266 | |
Willy Tarreau | df3231c | 2022-09-02 09:02:21 +0200 | [diff] [blame] | 1267 | #ifdef TLSEXT_TYPE_application_layer_protocol_negotiation |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1268 | if (ssl_sock_parse_alpn("h2,http/1.1", &srv_ssl->ssl_ctx.alpn_str, &srv_ssl->ssl_ctx.alpn_len, &errmsg) != 0) { |
Willy Tarreau | df3231c | 2022-09-02 09:02:21 +0200 | [diff] [blame] | 1269 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1270 | goto err; |
| 1271 | } |
| 1272 | #endif |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1273 | srv_ssl->ssl_ctx.verify = httpclient_ssl_verify; |
William Lallemand | 4006b0f | 2022-04-25 18:23:35 +0200 | [diff] [blame] | 1274 | /* if the verify is required, try to load the system CA */ |
William Lallemand | eaa703e | 2022-04-22 17:52:33 +0200 | [diff] [blame] | 1275 | if (httpclient_ssl_verify == SSL_SOCK_VERIFY_REQUIRED) { |
William Lallemand | 683fbb8 | 2022-05-04 15:43:01 +0200 | [diff] [blame] | 1276 | |
| 1277 | if (!httpclient_ssl_ca_file) |
| 1278 | httpclient_ssl_ca_file = strdup("@system-ca"); |
| 1279 | |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1280 | srv_ssl->ssl_ctx.ca_file = httpclient_ssl_ca_file; |
| 1281 | if (!ssl_store_load_locations_file(srv_ssl->ssl_ctx.ca_file, 1, CAFILE_CERT)) { |
William Lallemand | 6fce46a | 2022-05-04 14:53:41 +0200 | [diff] [blame] | 1282 | /* if we failed to load the ca-file, only quits in |
| 1283 | * error with hard_error, otherwise just disable the |
| 1284 | * feature. */ |
| 1285 | if (hard_error_ssl) { |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1286 | memprintf(&errmsg, "cannot initialize SSL verify with 'ca-file \"%s\"'.", srv_ssl->ssl_ctx.ca_file); |
William Lallemand | 6fce46a | 2022-05-04 14:53:41 +0200 | [diff] [blame] | 1287 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1288 | goto err; |
| 1289 | } else { |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1290 | ha_free(&srv_ssl->ssl_ctx.ca_file); |
| 1291 | srv_drop(srv_ssl); |
| 1292 | srv_ssl = NULL; |
William Lallemand | 6fce46a | 2022-05-04 14:53:41 +0200 | [diff] [blame] | 1293 | } |
William Lallemand | 4006b0f | 2022-04-25 18:23:35 +0200 | [diff] [blame] | 1294 | } |
William Lallemand | eaa703e | 2022-04-22 17:52:33 +0200 | [diff] [blame] | 1295 | } |
William Lallemand | cf5cb0b | 2022-04-22 14:48:45 +0200 | [diff] [blame] | 1296 | |
William Lallemand | 957ab13 | 2021-08-24 18:33:28 +0200 | [diff] [blame] | 1297 | #endif |
William Lallemand | cfcbe9e | 2021-08-24 17:15:58 +0200 | [diff] [blame] | 1298 | |
Ilya Shipitsin | bd6b4be | 2021-10-15 16:18:21 +0500 | [diff] [blame] | 1299 | /* add the proxy in the proxy list only if everything is successful */ |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1300 | px->next = proxies_list; |
| 1301 | proxies_list = px; |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1302 | |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1303 | if (httpclient_resolve_init(px) != 0) { |
William Lallemand | 85af49c | 2022-05-04 14:33:57 +0200 | [diff] [blame] | 1304 | memprintf(&errmsg, "cannot initialize resolvers."); |
| 1305 | err_code |= ERR_ALERT | ERR_FATAL; |
William Lallemand | 5392ff6 | 2022-04-28 16:55:02 +0200 | [diff] [blame] | 1306 | goto err; |
William Lallemand | 85af49c | 2022-05-04 14:33:57 +0200 | [diff] [blame] | 1307 | } |
William Lallemand | 5392ff6 | 2022-04-28 16:55:02 +0200 | [diff] [blame] | 1308 | |
William Lallemand | 211c967 | 2021-08-24 17:18:13 +0200 | [diff] [blame] | 1309 | /* link the 2 servers in the proxy */ |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1310 | srv_raw->next = px->srv; |
| 1311 | px->srv = srv_raw; |
William Lallemand | 957ab13 | 2021-08-24 18:33:28 +0200 | [diff] [blame] | 1312 | |
| 1313 | #ifdef USE_OPENSSL |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1314 | if (srv_ssl) { |
| 1315 | srv_ssl->next = px->srv; |
| 1316 | px->srv = srv_ssl; |
William Lallemand | 4006b0f | 2022-04-25 18:23:35 +0200 | [diff] [blame] | 1317 | } |
William Lallemand | 957ab13 | 2021-08-24 18:33:28 +0200 | [diff] [blame] | 1318 | #endif |
| 1319 | |
William Lallemand | 211c967 | 2021-08-24 17:18:13 +0200 | [diff] [blame] | 1320 | |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1321 | err: |
William Lallemand | 85af49c | 2022-05-04 14:33:57 +0200 | [diff] [blame] | 1322 | if (err_code & ERR_CODE) { |
| 1323 | ha_alert("httpclient: cannot initialize: %s\n", errmsg); |
| 1324 | free(errmsg); |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1325 | srv_drop(srv_raw); |
| 1326 | #ifdef USE_OPENSSL |
| 1327 | srv_drop(srv_ssl); |
| 1328 | #endif |
| 1329 | free_proxy(px); |
| 1330 | |
| 1331 | return NULL; |
| 1332 | } |
| 1333 | return px; |
| 1334 | } |
| 1335 | |
| 1336 | /* |
| 1337 | * Initialize the proxy for the HTTP client with 2 servers, one for raw HTTP, |
| 1338 | * the other for HTTPS. |
| 1339 | */ |
| 1340 | static int httpclient_precheck() |
| 1341 | { |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1342 | /* initialize the default httpclient_proxy which is used for the CLI and the lua */ |
| 1343 | |
| 1344 | httpclient_proxy = httpclient_create_proxy("<HTTPCLIENT>"); |
| 1345 | if (!httpclient_proxy) |
| 1346 | return 1; |
William Lallemand | 54aec5f | 2022-09-12 16:46:35 +0200 | [diff] [blame] | 1347 | |
| 1348 | return 0; |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1349 | } |
| 1350 | |
William Lallemand | 2c8b084 | 2022-04-22 15:16:09 +0200 | [diff] [blame] | 1351 | static int httpclient_postcheck() |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1352 | { |
William Lallemand | 85af49c | 2022-05-04 14:33:57 +0200 | [diff] [blame] | 1353 | int err_code = ERR_NONE; |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1354 | struct logsrv *logsrv; |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 1355 | struct proxy *curproxy = NULL; |
William Lallemand | 71e3158 | 2022-03-16 15:47:47 +0100 | [diff] [blame] | 1356 | char *errmsg = NULL; |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 1357 | #ifdef USE_OPENSSL |
| 1358 | struct server *srv = NULL; |
| 1359 | struct server *srv_ssl = NULL; |
| 1360 | #endif |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1361 | |
William Lallemand | c6ceba3 | 2022-04-22 16:49:53 +0200 | [diff] [blame] | 1362 | if (global.mode & MODE_MWORKER_WAIT) |
William Lallemand | 85af49c | 2022-05-04 14:33:57 +0200 | [diff] [blame] | 1363 | return ERR_NONE; |
William Lallemand | c6ceba3 | 2022-04-22 16:49:53 +0200 | [diff] [blame] | 1364 | |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 1365 | /* Initialize the logs for every proxy dedicated to the httpclient */ |
| 1366 | for (curproxy = proxies_list; curproxy; curproxy = curproxy->next) { |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1367 | |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 1368 | if (!(curproxy->cap & PR_CAP_HTTPCLIENT)) |
| 1369 | continue; |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1370 | |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 1371 | /* copy logs from "global" log list */ |
| 1372 | list_for_each_entry(logsrv, &global.logsrvs, list) { |
| 1373 | struct logsrv *node = malloc(sizeof(*node)); |
| 1374 | |
| 1375 | if (!node) { |
| 1376 | memprintf(&errmsg, "out of memory."); |
| 1377 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1378 | goto err; |
| 1379 | } |
| 1380 | |
| 1381 | memcpy(node, logsrv, sizeof(*node)); |
| 1382 | LIST_INIT(&node->list); |
| 1383 | LIST_APPEND(&curproxy->logsrvs, &node->list); |
| 1384 | node->ring_name = logsrv->ring_name ? strdup(logsrv->ring_name) : NULL; |
| 1385 | node->conf.file = logsrv->conf.file ? strdup(logsrv->conf.file) : NULL; |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1386 | } |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 1387 | if (curproxy->conf.logformat_string) { |
| 1388 | curproxy->conf.args.ctx = ARGC_LOG; |
| 1389 | if (!parse_logformat_string(curproxy->conf.logformat_string, curproxy, &curproxy->logformat, |
| 1390 | LOG_OPT_MANDATORY|LOG_OPT_MERGE_SPACES, |
| 1391 | SMP_VAL_FE_LOG_END, &errmsg)) { |
| 1392 | memprintf(&errmsg, "failed to parse log-format : %s.", errmsg); |
| 1393 | err_code |= ERR_ALERT | ERR_FATAL; |
| 1394 | goto err; |
| 1395 | } |
| 1396 | curproxy->conf.args.file = NULL; |
| 1397 | curproxy->conf.args.line = 0; |
| 1398 | } |
William Lallemand | 71e3158 | 2022-03-16 15:47:47 +0100 | [diff] [blame] | 1399 | |
| 1400 | #ifdef USE_OPENSSL |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 1401 | /* initialize the SNI for the SSL servers */ |
| 1402 | |
| 1403 | for (srv = curproxy->srv; srv != NULL; srv = srv->next) { |
| 1404 | if (srv->xprt == xprt_get(XPRT_SSL)) { |
| 1405 | srv_ssl = srv; |
| 1406 | } |
William Lallemand | 715c101 | 2022-03-16 16:39:23 +0100 | [diff] [blame] | 1407 | } |
Miroslav Zagorac | cbfee3a | 2022-09-19 12:20:29 +0200 | [diff] [blame] | 1408 | if (srv_ssl && !srv_ssl->sni_expr) { |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 1409 | /* init the SNI expression */ |
| 1410 | /* always use the host header as SNI, without the port */ |
| 1411 | srv_ssl->sni_expr = strdup("req.hdr(host),field(1,:)"); |
| 1412 | err_code |= server_parse_sni_expr(srv_ssl, curproxy, &errmsg); |
| 1413 | if (err_code & ERR_CODE) { |
| 1414 | memprintf(&errmsg, "failed to configure sni: %s.", errmsg); |
| 1415 | goto err; |
| 1416 | } |
| 1417 | } |
William Lallemand | 71e3158 | 2022-03-16 15:47:47 +0100 | [diff] [blame] | 1418 | #endif |
William Lallemand | 992ad62 | 2022-09-12 17:39:04 +0200 | [diff] [blame] | 1419 | } |
William Lallemand | 71e3158 | 2022-03-16 15:47:47 +0100 | [diff] [blame] | 1420 | |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1421 | err: |
William Lallemand | 85af49c | 2022-05-04 14:33:57 +0200 | [diff] [blame] | 1422 | if (err_code & ERR_CODE) { |
| 1423 | ha_alert("httpclient: failed to initialize: %s\n", errmsg); |
| 1424 | free(errmsg); |
| 1425 | |
| 1426 | } |
| 1427 | return err_code; |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1428 | } |
| 1429 | |
William Lallemand | 83614a9 | 2021-08-13 14:47:57 +0200 | [diff] [blame] | 1430 | /* initialize the proxy and servers for the HTTP client */ |
| 1431 | |
William Lallemand | 2c8b084 | 2022-04-22 15:16:09 +0200 | [diff] [blame] | 1432 | REGISTER_PRE_CHECK(httpclient_precheck); |
| 1433 | REGISTER_POST_CHECK(httpclient_postcheck); |
William Lallemand | eaa703e | 2022-04-22 17:52:33 +0200 | [diff] [blame] | 1434 | |
William Lallemand | 8a734cb | 2022-05-04 16:10:47 +0200 | [diff] [blame] | 1435 | static int httpclient_parse_global_resolvers(char **args, int section_type, struct proxy *curpx, |
| 1436 | const struct proxy *defpx, const char *file, int line, |
| 1437 | char **err) |
| 1438 | { |
| 1439 | if (too_many_args(1, args, err, NULL)) |
| 1440 | return -1; |
| 1441 | |
| 1442 | /* any configuration should set the hard_error flag */ |
| 1443 | hard_error_resolvers = 1; |
| 1444 | |
| 1445 | free(resolvers_id); |
| 1446 | resolvers_id = strdup(args[1]); |
| 1447 | |
| 1448 | return 0; |
| 1449 | } |
| 1450 | |
William Lallemand | 7c5a7ef | 2022-05-04 15:59:44 +0200 | [diff] [blame] | 1451 | static int httpclient_parse_global_prefer(char **args, int section_type, struct proxy *curpx, |
| 1452 | const struct proxy *defpx, const char *file, int line, |
| 1453 | char **err) |
| 1454 | { |
| 1455 | if (too_many_args(1, args, err, NULL)) |
| 1456 | return -1; |
| 1457 | |
| 1458 | /* any configuration should set the hard_error flag */ |
| 1459 | hard_error_resolvers = 1; |
| 1460 | |
| 1461 | |
| 1462 | if (strcmp(args[1],"ipv4") == 0) |
| 1463 | resolvers_prefer = "ipv4"; |
| 1464 | else if (strcmp(args[1],"ipv6") == 0) |
| 1465 | resolvers_prefer = "ipv6"; |
| 1466 | else { |
| 1467 | ha_alert("parsing [%s:%d] : '%s' expects 'ipv4' or 'ipv6' as argument.\n", file, line, args[0]); |
| 1468 | return -1; |
| 1469 | } |
| 1470 | |
| 1471 | return 0; |
| 1472 | } |
William Lallemand | 8a734cb | 2022-05-04 16:10:47 +0200 | [diff] [blame] | 1473 | |
| 1474 | |
William Lallemand | eaa703e | 2022-04-22 17:52:33 +0200 | [diff] [blame] | 1475 | #ifdef USE_OPENSSL |
William Lallemand | 683fbb8 | 2022-05-04 15:43:01 +0200 | [diff] [blame] | 1476 | static int httpclient_parse_global_ca_file(char **args, int section_type, struct proxy *curpx, |
| 1477 | const struct proxy *defpx, const char *file, int line, |
| 1478 | char **err) |
| 1479 | { |
| 1480 | if (too_many_args(1, args, err, NULL)) |
| 1481 | return -1; |
| 1482 | |
| 1483 | /* any configuration should set the hard_error flag */ |
| 1484 | hard_error_ssl = 1; |
| 1485 | |
| 1486 | free(httpclient_ssl_ca_file); |
| 1487 | httpclient_ssl_ca_file = strdup(args[1]); |
| 1488 | |
| 1489 | return 0; |
| 1490 | } |
| 1491 | |
William Lallemand | eaa703e | 2022-04-22 17:52:33 +0200 | [diff] [blame] | 1492 | static int httpclient_parse_global_verify(char **args, int section_type, struct proxy *curpx, |
| 1493 | const struct proxy *defpx, const char *file, int line, |
| 1494 | char **err) |
| 1495 | { |
| 1496 | if (too_many_args(1, args, err, NULL)) |
| 1497 | return -1; |
| 1498 | |
William Lallemand | 6fce46a | 2022-05-04 14:53:41 +0200 | [diff] [blame] | 1499 | /* any configuration should set the hard_error flag */ |
| 1500 | hard_error_ssl = 1; |
| 1501 | |
William Lallemand | eaa703e | 2022-04-22 17:52:33 +0200 | [diff] [blame] | 1502 | if (strcmp(args[1],"none") == 0) |
William Lallemand | 04994de | 2022-04-28 19:35:21 +0200 | [diff] [blame] | 1503 | httpclient_ssl_verify = SSL_SOCK_VERIFY_NONE; |
William Lallemand | eaa703e | 2022-04-22 17:52:33 +0200 | [diff] [blame] | 1504 | else if (strcmp(args[1],"required") == 0) |
William Lallemand | 04994de | 2022-04-28 19:35:21 +0200 | [diff] [blame] | 1505 | httpclient_ssl_verify = SSL_SOCK_VERIFY_REQUIRED; |
William Lallemand | eaa703e | 2022-04-22 17:52:33 +0200 | [diff] [blame] | 1506 | else { |
| 1507 | ha_alert("parsing [%s:%d] : '%s' expects 'none' or 'required' as argument.\n", file, line, args[0]); |
| 1508 | return -1; |
| 1509 | } |
| 1510 | |
| 1511 | return 0; |
| 1512 | } |
William Lallemand | 8a734cb | 2022-05-04 16:10:47 +0200 | [diff] [blame] | 1513 | #endif /* ! USE_OPENSSL */ |
William Lallemand | eaa703e | 2022-04-22 17:52:33 +0200 | [diff] [blame] | 1514 | |
| 1515 | static struct cfg_kw_list cfg_kws = {ILH, { |
William Lallemand | 8a734cb | 2022-05-04 16:10:47 +0200 | [diff] [blame] | 1516 | { CFG_GLOBAL, "httpclient.resolvers.id", httpclient_parse_global_resolvers }, |
William Lallemand | 7c5a7ef | 2022-05-04 15:59:44 +0200 | [diff] [blame] | 1517 | { CFG_GLOBAL, "httpclient.resolvers.prefer", httpclient_parse_global_prefer }, |
William Lallemand | 8a734cb | 2022-05-04 16:10:47 +0200 | [diff] [blame] | 1518 | #ifdef USE_OPENSSL |
William Lallemand | 9ff95e2 | 2022-05-04 13:52:29 +0200 | [diff] [blame] | 1519 | { CFG_GLOBAL, "httpclient.ssl.verify", httpclient_parse_global_verify }, |
William Lallemand | 683fbb8 | 2022-05-04 15:43:01 +0200 | [diff] [blame] | 1520 | { CFG_GLOBAL, "httpclient.ssl.ca-file", httpclient_parse_global_ca_file }, |
William Lallemand | 8a734cb | 2022-05-04 16:10:47 +0200 | [diff] [blame] | 1521 | #endif |
William Lallemand | eaa703e | 2022-04-22 17:52:33 +0200 | [diff] [blame] | 1522 | { 0, NULL, NULL }, |
| 1523 | }}; |
| 1524 | |
| 1525 | INITCALL1(STG_REGISTER, cfg_register_keywords, &cfg_kws); |