diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-12-17 11:59:07 +0000 |
commit | 8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca (patch) | |
tree | 544930fb309b30317ae9797a9683768705d664c4 /workhorse/internal/urlprefix | |
parent | 4b1de649d0168371549608993deac953eb692019 (diff) | |
download | gitlab-ce-8b573c94895dc0ac0e1d9d59cf3e8745e8b539ca.tar.gz |
Add latest changes from gitlab-org/gitlab@13-7-stable-eev13.7.0-rc42
Diffstat (limited to 'workhorse/internal/urlprefix')
-rw-r--r-- | workhorse/internal/urlprefix/urlprefix.go | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/workhorse/internal/urlprefix/urlprefix.go b/workhorse/internal/urlprefix/urlprefix.go new file mode 100644 index 00000000000..23eefe70c67 --- /dev/null +++ b/workhorse/internal/urlprefix/urlprefix.go @@ -0,0 +1,35 @@ +package urlprefix + +import ( + "path" + "strings" +) + +type Prefix string + +func (p Prefix) Strip(path string) string { + return CleanURIPath(strings.TrimPrefix(path, string(p))) +} + +func (p Prefix) Match(path string) bool { + pre := string(p) + return strings.HasPrefix(path, pre) || path+"/" == pre +} + +// Borrowed from: net/http/server.go +// Return the canonical path for p, eliminating . and .. elements. +func CleanURIPath(p string) string { + if p == "" { + return "/" + } + if p[0] != '/' { + p = "/" + p + } + np := path.Clean(p) + // path.Clean removes trailing slash except for root; + // put the trailing slash back if necessary. + if p[len(p)-1] == '/' && np != "/" { + np += "/" + } + return np +} |