MCPcopy
hub / github.com/harness/harness / TerminatedRegexPathBefore

Function TerminatedRegexPathBefore

app/api/middleware/encode/encode.go:148–168  ·  view source on GitHub ↗

TerminatedRegexPathBefore is similar to TerminatedPathBefore but supports regex prefixes.

(regexPrefixes []string, next http.Handler)

Source from the content-addressed store, hash-verified

146
147// TerminatedRegexPathBefore is similar to TerminatedPathBefore but supports regex prefixes.
148func 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.

Callers 2

NewAPIHandlerFunction · 0.92

Calls 3

TranslatedUserErrorFunction · 0.92
ServeHTTPMethod · 0.80

Tested by 1

Used in the wild real call sites across dependent graphs

searching dependent graphs…