Skip to content

Commit

Permalink
fix prefix path type if the path matches a domain
Browse files Browse the repository at this point in the history
Map keys are built using sysadmin/user defined hostnames and paths. We
concatenate both when building the map file, and also concatenate
hdr(host) and path from the incoming request. This works pretty well on
beg and reg match types. Since v0.11 we have also dir (Prefix from
ingress pathType) and str (Exact). The later also work well with this
construction, but str (Prefix) does not behave as expected from the end
user perspective.

Take this map example:

   domain.local/ backend1
   sub.domain.local/ backend2

and this request:

   sub.domain.local/domain.local

A begin or regex match type would choose backend2, and this is the
expected behavior for prefix as well, but due to how haproxy implements
-m dir, backend1 would be chosen.

When using dir match type, haproxy slices the request using the slash as
separator. These slices tries to match a whole map entry, but without
starting from the beginning.

A hash # is added after the hostname and before the first slash,
leaving the first item of the slice as unique. This is only needed for
dir / Prefix, but will not hurt other match types and does not have any
performance degradation.

Now the map looks like this:

   domain.local#/ backend1
   sub.domain.local#/ backend2

and the request is internally converted to this:

   sub.domain.local#/domain.local

Should be merged as far as v0.11.
  • Loading branch information
jcmoraisjr committed Mar 18, 2021
1 parent 463219a commit 1dde851
Show file tree
Hide file tree
Showing 4 changed files with 165 additions and 150 deletions.
Loading

0 comments on commit 1dde851

Please sign in to comment.