Commit 0e4fc277 authored by Gabor Pipicz's avatar Gabor Pipicz

Use json encoded request body for payload of POST and PUT

parent 9ab25f93
......@@ -17,6 +17,7 @@
package gitlab
import (
"bytes"
"encoding/json"
"errors"
"fmt"
......@@ -216,6 +217,19 @@ func (c *Client) NewRequest(method, path string, opt interface{}) (*http.Request
Host: u.Host,
}
if method == "POST" || method == "PUT" {
bodyBytes, err := json.Marshal(opt)
if err != nil {
return nil, err
}
bodyReader := bytes.NewReader(bodyBytes)
u.RawQuery = ""
req.Body = ioutil.NopCloser(bodyReader)
req.ContentLength = int64(bodyReader.Len())
req.Header.Set("Content-Type", "application/json")
}
req.Header.Set("Accept", "application/json")
req.Header.Set("PRIVATE-TOKEN", c.token)
if c.UserAgent != "" {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment