Browse Source

Fix for Discord's API returning a 400 Bad Request if Content-Type is set, but the request body is empty.

Eric Wohltman 5 years ago
parent
commit
307c335eb6
1 changed files with 6 additions and 1 deletions
  1. 6 1
      restapi.go

+ 6 - 1
restapi.go

@@ -88,7 +88,12 @@ func (s *Session) RequestWithLockedBucket(method, urlStr, contentType string, b
 		req.Header.Set("authorization", s.Token)
 	}
 
-	req.Header.Set("Content-Type", contentType)
+	// Discord's API returns a 400 Bad Request is Content-Type is set, but the
+	// request body is empty.
+	if b != nil {
+		req.Header.Set("Content-Type", contentType)
+	}
+
 	// TODO: Make a configurable static variable.
 	req.Header.Set("User-Agent", s.UserAgent)