TerminatedPathBefore wraps an http.HandlerFunc in a layer that encodes a terminated path (e.g. "/space1/space2/+") before executing the provided http.HandlerFunc. The first prefix that matches the URL.Path will be used during encoding (prefix is ignored during encoding).
(prefixes []string, next http.Handler)
| 123 | // before executing the provided http.HandlerFunc. The first prefix that matches the URL.Path will |
| 124 | // be used during encoding (prefix is ignored during encoding). |
| 125 | func TerminatedPathBefore(prefixes []string, next http.Handler) http.Handler { |
| 126 | return http.HandlerFunc( |
| 127 | func(w http.ResponseWriter, r *http.Request) { |
| 128 | ctx := r.Context() |
| 129 | for _, p := range prefixes { |
| 130 | changed, err := pathTerminatedWithMarker(r, p, "/+", "") |
| 131 | if err != nil { |
| 132 | render.TranslatedUserError(ctx, w, err) |
| 133 | return |
| 134 | } |
| 135 | |
| 136 | // first prefix that leads to success we can stop |
| 137 | if changed { |
| 138 | break |
| 139 | } |
| 140 | } |
| 141 | |
| 142 | next.ServeHTTP(w, r) |
| 143 | }, |
| 144 | ) |
| 145 | } |
| 146 | |
| 147 | // TerminatedRegexPathBefore is similar to TerminatedPathBefore but supports regex prefixes. |
| 148 | func TerminatedRegexPathBefore(regexPrefixes []string, next http.Handler) http.Handler { |
searching dependent graphs…