@@ -84,12 +84,14 @@ var (
8484 nullLatLon = "0.000000,0.000000"
8585)
8686
87- func findLocation (rw http.ResponseWriter , headers http.Header ) (string , string ) {
87+ func findLocation (rw http.ResponseWriter , req * http.Request ) (string , string ) {
88+ headers := req .Header
8889 fields := log.Fields {
8990 "CityLatLong" : headers .Get ("X-AppEngine-CityLatLong" ),
9091 "Country" : headers .Get ("X-AppEngine-Country" ),
9192 "Region" : headers .Get ("X-AppEngine-Region" ),
9293 "Proto" : headers .Get ("X-Forwarded-Proto" ),
94+ "Path" : req .URL .Path ,
9395 }
9496
9597 // First, try the given lat/lon. Avoid invalid values like 0,0.
@@ -126,9 +128,21 @@ func findLocation(rw http.ResponseWriter, headers http.Header) (string, string)
126128 return splitLatLon (latlon )
127129}
128130
131+ func clientValues (raw url.Values ) url.Values {
132+ v := url.Values {}
133+ for key := range raw {
134+ if strings .HasPrefix (key , "client_" ) {
135+ // note: we only use the first value.
136+ v .Set (key , raw .Get (key ))
137+ }
138+ }
139+ return v
140+ }
141+
129142// TranslatedQuery uses the legacy mlab-ns service for liveness as a
130143// transitional step in loading state directly.
131144func (c * Client ) TranslatedQuery (rw http.ResponseWriter , req * http.Request ) {
145+ req .ParseForm () // Parse any raw query parameters into req.Form url.Values.
132146 result := v2.NearestResult {}
133147 experiment , service := getExperimentAndService (req .URL .Path )
134148
@@ -148,7 +162,7 @@ func (c *Client) TranslatedQuery(rw http.ResponseWriter, req *http.Request) {
148162 }
149163
150164 // Make proxy request using AppEngine provided lat,lon.
151- lat , lon := findLocation (rw , req . Header )
165+ lat , lon := findLocation (rw , req )
152166 targets , err := c .Nearest (req .Context (), service , lat , lon )
153167 if err != nil {
154168 status := http .StatusInternalServerError
@@ -168,7 +182,7 @@ func (c *Client) TranslatedQuery(rw http.ResponseWriter, req *http.Request) {
168182 // Populate each set of URLs using the ports configuration.
169183 for i := range targets {
170184 token := c .getAccessToken (targets [i ].Machine , experiment )
171- targets [i ].URLs = c .getURLs (ports , targets [i ].Machine , experiment , token )
185+ targets [i ].URLs = c .getURLs (ports , targets [i ].Machine , experiment , token , clientValues ( req . Form ) )
172186 }
173187 result .Results = targets
174188 writeResult (rw , http .StatusOK , & result )
@@ -199,14 +213,18 @@ func (c *Client) getAccessToken(machine, subject string) string {
199213// getURLs creates URLs for the named experiment, running on the named machine
200214// for each given port. Every URL will include an `access_token=` parameter,
201215// authorizing the measurement.
202- func (c * Client ) getURLs (ports static.Ports , machine , experiment , token string ) map [string ]string {
216+ func (c * Client ) getURLs (ports static.Ports , machine , experiment , token string , extra url. Values ) map [string ]string {
203217 urls := map [string ]string {}
204218 // For each port config, prepare the target url with access_token and
205219 // complete host field.
206220 for _ , target := range ports {
207221 name := target .String ()
208222 params := url.Values {}
209223 params .Set ("access_token" , token )
224+ for key := range extra {
225+ // note: we only use the first value.
226+ params .Set (key , extra .Get (key ))
227+ }
210228 target .RawQuery = params .Encode ()
211229
212230 host := & bytes.Buffer {}
0 commit comments