feat(oonirun): add support for OONIRun v2 links (#844)

This diff adds support for OONIRun v2 links.

Part of https://github.com/ooni/probe/issues/2184.
This commit is contained in:
Simone Basso 2022-07-08 16:53:59 +02:00 committed by GitHub
commit 9a0153a349
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 644 additions and 22 deletions

View file

@ -148,21 +148,19 @@ func (c *apiClient) newRequestWithJSONBody(
return request, nil
}
// joinURLPath appends the path of resource URL to the baseURL taking
// care of multiple forward slashes gracefully.
func (c *apiClient) joinURLPath(origPath string, newPath string) string {
// If the BaseURL path doesn't end with a slash, added one
if !strings.HasSuffix(origPath, "/") {
origPath += "/"
// joinURLPath appends resourcePath to the urlPath.
func (c *apiClient) joinURLPath(urlPath, resourcePath string) string {
if resourcePath == "" {
if urlPath == "" {
return "/"
}
return urlPath
}
// If the resourceURL path has a leading slash, it is removed
if strings.HasPrefix(newPath, "/") {
newPath = newPath[1:]
if !strings.HasSuffix(urlPath, "/") {
urlPath += "/"
}
return origPath + newPath
resourcePath = strings.TrimPrefix(resourcePath, "/")
return urlPath + resourcePath
}
// newRequest creates a new request.