X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/e6617f0bff3521135bc63b229260fdfb7b9dc331..1166aeb6033725709ded753a0c00f69320a9a873:/sdk/go/arvados/client.go diff --git a/sdk/go/arvados/client.go b/sdk/go/arvados/client.go index 8625e7adef..a5815987b1 100644 --- a/sdk/go/arvados/client.go +++ b/sdk/go/arvados/client.go @@ -13,7 +13,6 @@ import ( "io" "io/ioutil" "log" - "math" "net/http" "net/url" "os" @@ -122,16 +121,16 @@ var reqIDGen = httpserver.IDGenerator{Prefix: "req-"} // Do adds Authorization and X-Request-Id headers and then calls // (*http.Client)Do(). func (c *Client) Do(req *http.Request) (*http.Response, error) { - if auth, _ := req.Context().Value("Authorization").(string); auth != "" { + if auth, _ := req.Context().Value(contextKeyAuthorization{}).(string); auth != "" { req.Header.Add("Authorization", auth) } else if c.AuthToken != "" { req.Header.Add("Authorization", "OAuth2 "+c.AuthToken) } if req.Header.Get("X-Request-Id") == "" { - reqid, _ := req.Context().Value(contextKeyRequestID).(string) + reqid, _ := req.Context().Value(contextKeyRequestID{}).(string) if reqid == "" { - reqid, _ = c.context().Value(contextKeyRequestID).(string) + reqid, _ = c.context().Value(contextKeyRequestID{}).(string) } if reqid == "" { reqid = reqIDGen.Next() @@ -188,7 +187,9 @@ func anythingToValues(params interface{}) (url.Values, error) { return nil, err } var generic map[string]interface{} - err = json.Unmarshal(j, &generic) + dec := json.NewDecoder(bytes.NewBuffer(j)) + dec.UseNumber() + err = dec.Decode(&generic) if err != nil { return nil, err } @@ -198,22 +199,27 @@ func anythingToValues(params interface{}) (url.Values, error) { urlValues.Set(k, v) continue } - if v, ok := v.(float64); ok { - // Unmarshal decodes all numbers as float64, - // which can be written as 1.2345e4 in JSON, - // but this form is not accepted for ints in - // url params. If a number fits in an int64, - // encode it as int64 rather than float64. - if v, frac := math.Modf(v); frac == 0 && v <= math.MaxInt64 && v >= math.MinInt64 { - urlValues.Set(k, fmt.Sprintf("%d", int64(v))) - continue + if v, ok := v.(json.Number); ok { + urlValues.Set(k, v.String()) + continue + } + if v, ok := v.(bool); ok { + if v { + urlValues.Set(k, "true") + } else { + // "foo=false", "foo=0", and "foo=" + // are all taken as true strings, so + // don't send false values at all -- + // rely on the default being false. } + continue } j, err := json.Marshal(v) if err != nil { return nil, err } - if string(j) == "null" { + if bytes.Equal(j, []byte("null")) { + // don't add it to urlValues at all continue } urlValues.Set(k, string(j))