Skip to content

Commit

Permalink
Merge pull request #15 from UpperM/fix/avoid-sendig-body-on-get-request
Browse files Browse the repository at this point in the history
fix(request): don't add body on GET request
  • Loading branch information
pavel-z1 authored May 13, 2023
2 parents 21f3f01 + 275b2fa commit 6fea0cb
Showing 1 changed file with 11 additions and 13 deletions.
24 changes: 11 additions & 13 deletions phpipam/request/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -146,24 +146,22 @@ func (r *Request) Send() error {
}

switch r.Method {
case "OPTIONS", "GET", "POST", "PUT", "PATCH", "DELETE":
if r.Input != nil {
bs, err := json.Marshal(r.Input)
log.Debugf("Request Body Debug ................... %s", bs)
if err != nil {
return fmt.Errorf("Error preparing request data: %s", err)
}
buf := bytes.NewBuffer(bs)
req, err = http.NewRequest(r.Method, fmt.Sprintf("%s/%s%s", r.Session.Config.Endpoint, r.Session.Config.AppID, r.URI), buf)
} else {
req, err = http.NewRequest(r.Method, fmt.Sprintf("%s/%s%s", r.Session.Config.Endpoint, r.Session.Config.AppID, r.URI), nil)
case "OPTIONS", "POST", "PUT", "PATCH", "DELETE":
bs, err := json.Marshal(r.Input)
log.Debugf("Request Body Debug ................... %s", bs)
if err != nil {
return fmt.Errorf("Error preparing request data: %s", err)
}

buf := bytes.NewBuffer(bs)
req, err = http.NewRequest(r.Method, fmt.Sprintf("%s/%s%s", r.Session.Config.Endpoint, r.Session.Config.AppID, r.URI), buf)
req.Header.Add("Content-Type", "application/json")
log.Debugf("Request URL Debug ...................Method: %s, UR: %s/%s%s", r.Method, r.Session.Config.Endpoint, r.Session.Config.AppID, r.URI)
case "GET":
req, err = http.NewRequest(r.Method, fmt.Sprintf("%s/%s%s", r.Session.Config.Endpoint, r.Session.Config.AppID, r.URI), nil)

default:
return fmt.Errorf("API request method %s not supported by PHPIPAM", r.Method)
}
log.Debugf("Request URL Debug ...................Method: %s, UR: %s/%s%s", r.Method, r.Session.Config.Endpoint, r.Session.Config.AppID, r.URI)

if err != nil {
panic(err)
Expand Down

0 comments on commit 6fea0cb

Please sign in to comment.