(ef EndpointFinder, operation, remote string, apiEndpoint lfshttp.Endpoint, req *http.Request)
| 197 | } |
| 198 | |
| 199 | func getCredURLForAPI(ef EndpointFinder, operation, remote string, apiEndpoint lfshttp.Endpoint, req *http.Request) (*url.URL, error) { |
| 200 | apiURL, err := url.Parse(apiEndpoint.Url) |
| 201 | if err != nil { |
| 202 | return nil, err |
| 203 | } |
| 204 | |
| 205 | // if the LFS request doesn't match the current LFS url, don't bother |
| 206 | // attempting to set the Authorization header from the LFS or Git remote URLs. |
| 207 | if req.URL.Scheme != apiURL.Scheme || |
| 208 | req.URL.Host != apiURL.Host { |
| 209 | return req.URL, nil |
| 210 | } |
| 211 | |
| 212 | if setRequestAuthFromURL(req, apiURL) { |
| 213 | return nil, nil |
| 214 | } |
| 215 | |
| 216 | if len(remote) > 0 { |
| 217 | if u := ef.GitRemoteURL(remote, operation == "upload"); u != "" { |
| 218 | schemedUrl, _ := fixSchemelessURL(u) |
| 219 | |
| 220 | gitRemoteURL, err := url.Parse(schemedUrl) |
| 221 | if err != nil { |
| 222 | return nil, err |
| 223 | } |
| 224 | |
| 225 | if gitRemoteURL.Scheme == apiURL.Scheme && |
| 226 | gitRemoteURL.Host == apiURL.Host { |
| 227 | |
| 228 | if setRequestAuthFromURL(req, gitRemoteURL) { |
| 229 | return nil, nil |
| 230 | } |
| 231 | |
| 232 | return gitRemoteURL, nil |
| 233 | } |
| 234 | } |
| 235 | } |
| 236 | |
| 237 | return apiURL, nil |
| 238 | } |
| 239 | |
| 240 | // fixSchemelessURL prepends an empty scheme "//" if none was found in |
| 241 | // the URL and replaces the first colon with a slash in order to satisfy RFC |
no test coverage detected