From: Willy Tarreau Date: Wed, 23 Sep 2020 06:56:29 +0000 (+0200) Subject: MINOR: backend: add a new "path-only" option to "balance uri" X-Git-Tag: v2.3-dev5~5 X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=57a374131cd3c1c46f9d78ea9c0f2ad027d0be97;p=thirdparty%2Fhaproxy.git MINOR: backend: add a new "path-only" option to "balance uri" Since we've fixed the way URIs are handled in 2.1, some users have started to experience inconsistencies in "balance uri" between requests received over H1 and the same ones received over H2. This is caused by the fact that H1 rarely uses absolute URIs while H2 always uses them. Similar issues were reported already around replace-uri etc, leading to "pathq" recently being introduced, so this isn't new. Here what this patch does is add a new option to "balance uri" to indicate that the hashing should only start at the path and not cover the authority. This makes H1 relative URIs and H2 absolute URI hashes equally again. Some extra options could be added to normalize URIs by always hashing the authority (or host) in front of them, which would make sure that both absolute and relative requests provide the same hash. This is left for later if needed. --- diff --git a/doc/configuration.txt b/doc/configuration.txt index 3757a50027..2304c45b3d 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -3211,6 +3211,11 @@ balance url_param [check_post] slash in the request. If both parameters are specified, the evaluation stops when either is reached. + A "path-only" parameter indicates that the hashing key starts + at the first '/' of the path. This can be used to ignore the + authority part of absolute URIs, and to make sure that HTTP/1 + and HTTP/2 URIs will provide the same hash. + url_param The URL parameter specified in argument will be looked up in the query string of each HTTP GET request. diff --git a/src/backend.c b/src/backend.c index 445c73a971..44cda1a281 100644 --- a/src/backend.c +++ b/src/backend.c @@ -701,6 +701,11 @@ int assign_server(struct stream *s) struct ist uri; uri = htx_sl_req_uri(http_get_stline(htxbuf(&s->req.buf))); + if (s->be->lbprm.arg_opt1 & 2) { + uri = http_get_path(uri); + if (!uri.ptr) + uri = ist(""); + } srv = get_server_uh(s->be, uri.ptr, uri.len, prev_srv); } break; @@ -2374,7 +2379,7 @@ int backend_parse_balance(const char **args, char **err, struct proxy *curproxy) curproxy->lbprm.algo &= ~BE_LB_ALGO; curproxy->lbprm.algo |= BE_LB_ALGO_UH; - curproxy->lbprm.arg_opt1 = 0; // "whole" + curproxy->lbprm.arg_opt1 = 0; // "whole", "path-only" curproxy->lbprm.arg_opt2 = 0; // "len" curproxy->lbprm.arg_opt3 = 0; // "depth" @@ -2402,8 +2407,12 @@ int backend_parse_balance(const char **args, char **err, struct proxy *curproxy) curproxy->lbprm.arg_opt1 |= 1; arg += 1; } + else if (!strcmp(args[arg], "path-only")) { + curproxy->lbprm.arg_opt1 |= 2; + arg += 1; + } else { - memprintf(err, "%s only accepts parameters 'len', 'depth', and 'whole' (got '%s').", args[0], args[arg]); + memprintf(err, "%s only accepts parameters 'len', 'depth', 'path-only', and 'whole' (got '%s').", args[0], args[arg]); return -1; } }