MCPcopy
hub / github.com/harness/harness / TerminatedPathBefore

Function TerminatedPathBefore

app/api/middleware/encode/encode.go:125–145  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

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).
125func 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.
148func TerminatedRegexPathBefore(regexPrefixes []string, next http.Handler) http.Handler {

Callers 3

NewAPIHandlerFunction · 0.92
NewAPIHandlerFunction · 0.92
TestTerminatedPathBeforeFunction · 0.85

Calls 3

TranslatedUserErrorFunction · 0.92
pathTerminatedWithMarkerFunction · 0.85
ServeHTTPMethod · 0.80

Tested by 1

TestTerminatedPathBeforeFunction · 0.68

Used in the wild real call sites across dependent graphs

searching dependent graphs…