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.
This commit is contained in:
Willy Tarreau 2020-09-23 08:56:29 +02:00
parent 3d1119d225
commit 57a374131c
2 changed files with 16 additions and 2 deletions

View File

@ -3211,6 +3211,11 @@ balance url_param <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.

View File

@ -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;
}
}