pathTerminatedWithMarker function encodes a path followed by a custom marker and returns a request with an updated URL.Path. A non-empty prefix can be provided to encode only after the prefix. It allows our Rest API to handle paths of the form "/spaces/space1/space2/+/authToken" Examples: Prefix: "
(r *http.Request, prefix string, marker string, markerReplacement string)
| 177 | // Prefix: "" Path: "/space1/.gitness.git" => "/space1%2F.gitness" |
| 178 | // Prefix: "/spaces" Path: "/spaces/space1/space2/+/authToken" => "/spaces/space1%2Fspace2/authToken". |
| 179 | func pathTerminatedWithMarker(r *http.Request, prefix string, marker string, markerReplacement string) (bool, error) { |
| 180 | // r.URL.Path contains URL-decoded URI path. r.URL.RawPath contains raw URI path. But, if the URI don't contain |
| 181 | // any character that needs encoding, the r.URL.RawPath is empty (otherwise it would be equal to r.URL.Path). |
| 182 | |
| 183 | // We work with r.URL.RawPath it is exist, or with r.URL.Path if the r.URL.RawPath is empty. |
| 184 | urlPath := r.URL.Path |
| 185 | if r.URL.RawPath != "" { |
| 186 | urlPath = r.URL.RawPath |
| 187 | } |
| 188 | |
| 189 | return pathTerminatedWithMarkerAndURL(r, prefix, marker, markerReplacement, urlPath) |
| 190 | } |
| 191 | |
| 192 | func pathTerminatedWithMarkerAndURL( |
| 193 | r *http.Request, prefix string, marker string, markerReplacement string, urlPath string, |
no test coverage detected
searching dependent graphs…