diff --git a/doc/configuration.txt b/doc/configuration.txt index 3fc77a0ca..1253357b0 100644 --- a/doc/configuration.txt +++ b/doc/configuration.txt @@ -1311,18 +1311,20 @@ balance url_param [check_post []] weight on the fly will have no effect, but this can be changed using "hash-type". - uri The left part of the URI (before the question mark) is hashed - and divided by the total weight of the running servers. The - result designates which server will receive the request. This - ensures that a same URI will always be directed to the same - server as long as no server goes up or down. This is used - with proxy caches and anti-virus proxies in order to maximize - the cache hit rate. Note that this algorithm may only be used - in an HTTP backend. This algorithm is static by default, - which means that changing a server's weight on the fly will - have no effect, but this can be changed using "hash-type". + uri This algorithm hashes either the left part of the URI (before + the question mark) or the whole URI (if the "whole" parameter + is present) and divides the hash value by the total weight of + the running servers. The result designates which server will + receive the request. This ensures that the same URI will + always be directed to the same server as long as no server + goes up or down. This is used with proxy caches and + anti-virus proxies in order to maximize the cache hit rate. + Note that this algorithm may only be used in an HTTP backend. + This algorithm is static by default, which means that + changing a server's weight on the fly will have no effect, + but this can be changed using "hash-type". - This algorithm support two optional parameters "len" and + This algorithm supports two optional parameters "len" and "depth", both followed by a positive integer number. These options may be helpful when it is needed to balance servers based on the beginning of the URI only. The "len" parameter diff --git a/include/types/proxy.h b/include/types/proxy.h index a94eee767..622e1686c 100644 --- a/include/types/proxy.h +++ b/include/types/proxy.h @@ -239,6 +239,7 @@ struct proxy { unsigned url_param_post_limit; /* if checking POST body for URI parameter, max body to wait for */ int uri_len_limit; /* character limit for uri balancing algorithm */ int uri_dirs_depth1; /* directories+1 (slashes) limit for uri balancing algorithm */ + int uri_whole; /* if != 0, calculates the hash from the whole uri. Still honors the len_limit and dirs_depth1 */ char *hh_name; /* name of the header parameter used for hashing */ int hh_len; /* strlen(hh_name), computed only once */ int hh_match_domain; /* toggle use of special match function */ diff --git a/src/backend.c b/src/backend.c index 31f1a0fbd..e3a64e914 100644 --- a/src/backend.c +++ b/src/backend.c @@ -167,7 +167,7 @@ struct server *get_server_uh(struct proxy *px, char *uri, int uri_len) if (slashes == px->uri_dirs_depth1) /* depth+1 */ break; } - else if (c == '?') + else if (c == '?' && !px->uri_whole) break; hash = c + (hash << 6) + (hash << 16) - hash; @@ -1264,6 +1264,8 @@ 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->uri_whole = 0; + while (*args[arg]) { if (!strcmp(args[arg], "len")) { if (!*args[arg+1] || (atoi(args[arg+1]) <= 0)) { @@ -1284,8 +1286,12 @@ int backend_parse_balance(const char **args, char **err, struct proxy *curproxy) curproxy->uri_dirs_depth1 = atoi(args[arg+1]) + 1; arg += 2; } + else if (!strcmp(args[arg], "whole")) { + curproxy->uri_whole = 1; + arg += 1; + } else { - memprintf(err, "%s only accepts parameters 'len' and 'depth' (got '%s').", args[0], args[arg]); + memprintf(err, "%s only accepts parameters 'len', 'depth', and 'whole' (got '%s').", args[0], args[arg]); return -1; } }