From 5452a224bf619dd256d7906e55dad440c49e36e0 Mon Sep 17 00:00:00 2001 From: Eric Wohltman Date: Thu, 19 Dec 2019 12:46:45 -0500 Subject: [PATCH] Fix for Discord's API returning a 400 Bad Request if Content-Type is set, but the request body is empty. --- restapi.go | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/restapi.go b/restapi.go index 8134d92..69c5507 100644 --- a/restapi.go +++ b/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)