diff --git a/tsuru/services.go b/tsuru/services.go index 8239661a7..dbe37a9b5 100644 --- a/tsuru/services.go +++ b/tsuru/services.go @@ -13,6 +13,7 @@ import ( "net/http" "net/url" "sort" + "strconv" "strings" "github.com/tsuru/gnuflag" @@ -188,15 +189,17 @@ func (sb *serviceInstanceBind) Run(ctx *cmd.Context, client *cmd.Client) error { } serviceName := ctx.Args[0] instanceName := ctx.Args[1] - url, err := cmd.GetURL("/services/" + serviceName + "/instances/" + instanceName + "/" + appName) + u, err := cmd.GetURL("/services/" + serviceName + "/instances/" + instanceName + "/" + appName) if err != nil { return err } - url += fmt.Sprintf("?noRestart=%t", sb.noRestart) - request, err := http.NewRequest("PUT", url, nil) + v := url.Values{} + v.Set("noRestart", strconv.FormatBool(sb.noRestart)) + request, err := http.NewRequest("PUT", u, strings.NewReader(v.Encode())) if err != nil { return err } + request.Header.Set("Content-Type", "application/x-www-form-urlencoded") resp, err := client.Do(request) if err != nil { return err diff --git a/tsuru/services_test.go b/tsuru/services_test.go index f94b5bf07..197b4e75c 100644 --- a/tsuru/services_test.go +++ b/tsuru/services_test.go @@ -155,8 +155,10 @@ func (s *S) TestServiceBind(c *check.C) { Transport: cmdtest.Transport{Message: string(result), Status: http.StatusOK}, CondFunc: func(req *http.Request) bool { called = true - return req.Method == "PUT" && strings.HasSuffix(req.URL.Path, "/services/mysql/instances/my-mysql/g1") && - req.URL.RawQuery == "noRestart=true" + method := req.Method == "PUT" + path := strings.HasSuffix(req.URL.Path, "/services/mysql/instances/my-mysql/g1") + noRestart := req.FormValue("noRestart") == "true" + return method && path && noRestart }, } client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager) @@ -189,8 +191,10 @@ func (s *S) TestServiceBindWithoutFlag(c *check.C) { }, CondFunc: func(req *http.Request) bool { called = true - return req.Method == "PUT" && strings.HasSuffix(req.URL.Path, "/services/mysql/instances/my-mysql/ge") && - req.URL.RawQuery == "noRestart=false" + method := req.Method == "PUT" + path := strings.HasSuffix(req.URL.Path, "/services/mysql/instances/my-mysql/ge") + noRestart := req.FormValue("noRestart") == "false" + return method && path && noRestart }, } client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager) @@ -215,8 +219,10 @@ func (s *S) TestServiceBindWithoutEnvironmentVariables(c *check.C) { trans := &cmdtest.ConditionalTransport{ Transport: cmdtest.Transport{Message: string(result), Status: http.StatusOK}, CondFunc: func(req *http.Request) bool { - return req.Method == "PUT" && strings.HasSuffix(req.URL.Path, "/services/mysql/instances/my-mysql/g1") && - req.URL.RawQuery == "noRestart=false" + method := req.Method == "PUT" + path := strings.HasSuffix(req.URL.Path, "/services/mysql/instances/my-mysql/g1") + noRestart := req.FormValue("noRestart") == "false" + return method && path && noRestart }, } client := cmd.NewClient(&http.Client{Transport: trans}, nil, manager)