Skip to content

Commit 6fea0cb

Browse files
authored
Merge pull request #15 from UpperM/fix/avoid-sendig-body-on-get-request
fix(request): don't add body on GET request
2 parents 21f3f01 + 275b2fa commit 6fea0cb

File tree

1 file changed

+11
-13
lines changed

1 file changed

+11
-13
lines changed

phpipam/request/request.go

+11-13
Original file line numberDiff line numberDiff line change
@@ -146,24 +146,22 @@ func (r *Request) Send() error {
146146
}
147147

148148
switch r.Method {
149-
case "OPTIONS", "GET", "POST", "PUT", "PATCH", "DELETE":
150-
if r.Input != nil {
151-
bs, err := json.Marshal(r.Input)
152-
log.Debugf("Request Body Debug ................... %s", bs)
153-
if err != nil {
154-
return fmt.Errorf("Error preparing request data: %s", err)
155-
}
156-
buf := bytes.NewBuffer(bs)
157-
req, err = http.NewRequest(r.Method, fmt.Sprintf("%s/%s%s", r.Session.Config.Endpoint, r.Session.Config.AppID, r.URI), buf)
158-
} else {
159-
req, err = http.NewRequest(r.Method, fmt.Sprintf("%s/%s%s", r.Session.Config.Endpoint, r.Session.Config.AppID, r.URI), nil)
149+
case "OPTIONS", "POST", "PUT", "PATCH", "DELETE":
150+
bs, err := json.Marshal(r.Input)
151+
log.Debugf("Request Body Debug ................... %s", bs)
152+
if err != nil {
153+
return fmt.Errorf("Error preparing request data: %s", err)
160154
}
161-
155+
buf := bytes.NewBuffer(bs)
156+
req, err = http.NewRequest(r.Method, fmt.Sprintf("%s/%s%s", r.Session.Config.Endpoint, r.Session.Config.AppID, r.URI), buf)
162157
req.Header.Add("Content-Type", "application/json")
163-
log.Debugf("Request URL Debug ...................Method: %s, UR: %s/%s%s", r.Method, r.Session.Config.Endpoint, r.Session.Config.AppID, r.URI)
158+
case "GET":
159+
req, err = http.NewRequest(r.Method, fmt.Sprintf("%s/%s%s", r.Session.Config.Endpoint, r.Session.Config.AppID, r.URI), nil)
160+
164161
default:
165162
return fmt.Errorf("API request method %s not supported by PHPIPAM", r.Method)
166163
}
164+
log.Debugf("Request URL Debug ...................Method: %s, UR: %s/%s%s", r.Method, r.Session.Config.Endpoint, r.Session.Config.AppID, r.URI)
167165

168166
if err != nil {
169167
panic(err)

0 commit comments

Comments
 (0)