( r *http.Request, prefix string, marker string, markerReplacement string, urlPath string, )
| 190 | } |
| 191 | |
| 192 | func 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 | // |
no test coverage detected
searching dependent graphs…