diff --git a/doc/configuration.txt b/doc/configuration.txt index 3757a5002..2304c45b3 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 445c73a97..44cda1a28 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; } }