| 174 | } |
| 175 | |
| 176 | func (wc *workerConfig) matchesPath(r *http.Request, documentRoot string) bool { |
| 177 | // try to match against a pattern if one is assigned |
| 178 | if len(wc.MatchPath) != 0 { |
| 179 | return (caddyhttp.MatchPath)(wc.MatchPath).Match(r) |
| 180 | } |
| 181 | |
| 182 | // fast path: compare the request URL path against the pre-computed relative path |
| 183 | if wc.matchRelPath != "" { |
| 184 | reqPath := r.URL.Path |
| 185 | if reqPath == wc.matchRelPath { |
| 186 | return true |
| 187 | } |
| 188 | |
| 189 | // ensure leading slash for relative paths (see #2166) |
| 190 | if reqPath == "" || reqPath[0] != '/' { |
| 191 | reqPath = "/" + reqPath |
| 192 | } |
| 193 | |
| 194 | return path.Clean(reqPath) == wc.matchRelPath |
| 195 | } |
| 196 | |
| 197 | // fallback when documentRoot is dynamic (contains placeholders) |
| 198 | fullPath, _ := fastabs.FastAbs(filepath.Join(documentRoot, r.URL.Path)) |
| 199 | |
| 200 | return fullPath == wc.absFileName |
| 201 | } |