Skip to content

Commit

Permalink
Add locate_version parameter to output urls (#97)
Browse files Browse the repository at this point in the history
* Add locate_version parameter to output urls

* Add comments
  • Loading branch information
cristinaleonr authored Dec 5, 2022
1 parent 40a7737 commit 64a9a1d
Showing 1 changed file with 8 additions and 5 deletions.
13 changes: 8 additions & 5 deletions handler/handler.go
Original file line number Diff line number Diff line change
Expand Up @@ -102,14 +102,17 @@ func NewClientDirect(project string, private Signer, locator Locator, locatorV2
}
}

func clientValues(raw url.Values) url.Values {
func extraParams(raw url.Values, version string) url.Values {
v := url.Values{}
// Add client parameters.
for key := range raw {
if strings.HasPrefix(key, "client_") {
// note: we only use the first value.
v.Set(key, raw.Get(key))
}
}
// Add Locate Service version.
v.Set("locate_version", version)
return v
}

Expand Down Expand Up @@ -153,7 +156,7 @@ func (c *Client) TranslatedQuery(rw http.ResponseWriter, req *http.Request) {
}

// Populate targets URLs and write out response.
c.populateURLs(targets, ports, experiment, req.Form)
c.populateURLs(targets, ports, experiment, "v2_proxy", req.Form)
result.Results = targets
writeResult(rw, http.StatusOK, &result)
}
Expand Down Expand Up @@ -198,7 +201,7 @@ func (c *Client) Nearest(rw http.ResponseWriter, req *http.Request) {
}

// Populate target URLs and write out response.
c.populateURLs(targets, urls, experiment, req.Form)
c.populateURLs(targets, urls, experiment, "v2", req.Form)
result.Results = targets
writeResult(rw, http.StatusOK, &result)
metrics.RequestsTotal.WithLabelValues("nearest", http.StatusText(http.StatusOK)).Inc()
Expand All @@ -222,10 +225,10 @@ func (c *Client) checkClientLocation(rw http.ResponseWriter, req *http.Request)
}

// populateURLs populates each set of URLs using the target configuration.
func (c *Client) populateURLs(targets []v2.Target, ports static.Ports, exp string, form url.Values) {
func (c *Client) populateURLs(targets []v2.Target, ports static.Ports, exp, version string, form url.Values) {
for i := range targets {
token := c.getAccessToken(targets[i].Machine, exp)
targets[i].URLs = c.getURLs(ports, targets[i].Machine, exp, token, clientValues(form))
targets[i].URLs = c.getURLs(ports, targets[i].Machine, exp, token, extraParams(form, version))
}
}

Expand Down

0 comments on commit 64a9a1d

Please sign in to comment.