MCPcopy Create free account
hub / github.com/imgproxy/imgproxy / SplitPathSignature

Function SplitPathSignature

handlers/path.go:14–38  ·  view source on GitHub ↗

SplitPathSignature splits signature and path components from the request URI

(r *http.Request)

Source from the content-addressed store, hash-verified

12
13// SplitPathSignature splits signature and path components from the request URI
14func SplitPathSignature(r *http.Request) (string, string, error) {
15 uri := r.RequestURI
16
17 // cut query params
18 uri, _, _ = strings.Cut(uri, "?")
19
20 // Cut path prefix.
21 // r.Pattern is set by the router and contains both global and route-specific prefixes combined.
22 if len(r.Pattern) > 0 {
23 uri = strings.TrimPrefix(uri, r.Pattern)
24 }
25
26 // cut leading slash
27 uri = strings.TrimPrefix(uri, "/")
28
29 signature, path, _ := strings.Cut(uri, "/")
30 if len(signature) == 0 || len(path) == 0 {
31 return "", "", NewInvalidPathError(r.Context(), path)
32 }
33
34 // restore broken slashes in the path
35 path = RedenormalizePath(path)
36
37 return path, signature, nil
38}
39
40// RedenormalizePath undoes path normalization done by some browsers and revers proxies.
41// Also trims leading slash if it is present.

Callers 2

TestParsePathMethod · 0.92
newRequestMethod · 0.92

Calls 2

NewInvalidPathErrorFunction · 0.85
RedenormalizePathFunction · 0.85

Tested by 1

TestParsePathMethod · 0.74