MCPcopy
hub / github.com/harness/harness / pathTerminatedWithMarkerAndURL

Function pathTerminatedWithMarkerAndURL

app/api/middleware/encode/encode.go:192–227  ·  view source on GitHub ↗
(
	r *http.Request, prefix string, marker string, markerReplacement string, urlPath string,
)

Source from the content-addressed store, hash-verified

190}
191
192func pathTerminatedWithMarkerAndURL(
193 r *http.Request, prefix string, marker string, markerReplacement string, urlPath string,
194) (bool, error) {
195 // In case path doesn't start with prefix - nothing to encode
196 if len(urlPath) < len(prefix) || urlPath[0:len(prefix)] != prefix {
197 return false, nil
198 }
199
200 originalSubPath := urlPath[len(prefix):]
201 path, found := cutOutTerminatedPath(originalSubPath, marker)
202 if !found {
203 // If we don't find a marker - nothing to encode
204 return false, nil
205 }
206
207 // if marker was found - convert to escaped version (skip first character in case path starts with '/').
208 escapedPath := path[0:1] + strings.ReplaceAll(path[1:], types.PathSeparatorAsString, EncodedPathSeparator)
209
210 prefixWithPath := prefix + path + marker
211 prefixWithEscapedPath := prefix + escapedPath + markerReplacement
212
213 hlog.FromRequest(r).Trace().Msgf(
214 "[Encode] prefix: '%s', marker: '%s', original: '%s', escaped: '%s'.\n",
215 prefix,
216 marker,
217 prefixWithPath,
218 prefixWithEscapedPath,
219 )
220
221 err := request.ReplacePrefix(r, prefixWithPath, prefixWithEscapedPath)
222 if err != nil {
223 return false, err
224 }
225
226 return true, nil
227}
228
229// regexPathTerminatedWithMarker is similar to pathTerminatedWithMarker but with regex prefix support.
230//

Callers 3

processGitRequestFunction · 0.85
pathTerminatedWithMarkerFunction · 0.85

Calls 4

ReplacePrefixFunction · 0.92
cutOutTerminatedPathFunction · 0.85
MsgfMethod · 0.80
TraceMethod · 0.80

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…