TerminatedRegexPathBefore is similar to TerminatedPathBefore but supports regex prefixes.
(regexPrefixes []string, next http.Handler)
| 146 | |
| 147 | // TerminatedRegexPathBefore is similar to TerminatedPathBefore but supports regex prefixes. |
| 148 | func TerminatedRegexPathBefore(regexPrefixes []string, next http.Handler) http.Handler { |
| 149 | return http.HandlerFunc( |
| 150 | func(w http.ResponseWriter, r *http.Request) { |
| 151 | ctx := r.Context() |
| 152 | for _, p := range regexPrefixes { |
| 153 | changed, err := regexPathTerminatedWithMarker(r, p, "/+", "") |
| 154 | if err != nil { |
| 155 | render.TranslatedUserError(ctx, w, err) |
| 156 | return |
| 157 | } |
| 158 | |
| 159 | // first prefix that leads to success we can stop |
| 160 | if changed { |
| 161 | break |
| 162 | } |
| 163 | } |
| 164 | |
| 165 | next.ServeHTTP(w, r) |
| 166 | }, |
| 167 | ) |
| 168 | } |
| 169 | |
| 170 | // pathTerminatedWithMarker function encodes a path followed by a custom marker and returns a request with an |
| 171 | // updated URL.Path. |
searching dependent graphs…