From 32761dadd755ae27beeb7663948d362aef6bddf0 Mon Sep 17 00:00:00 2001
From: Christophe Gachiniard <cgachiniard@twitter.com>
Date: Thu, 20 Oct 2022 15:13:59 +0200
Subject: [PATCH] request body for PUT calls

---
 src/request.ts | 6 +++---
 1 file changed, 3 insertions(+), 3 deletions(-)

diff --git a/src/request.ts b/src/request.ts
index bd5f95d..fd2c651 100644
--- a/src/request.ts
+++ b/src/request.ts
@@ -84,7 +84,7 @@ export async function request({
 }: RequestOptions): Promise<Response> {
   const url = new URL(base_url + endpoint);
   url.search = buildQueryString(query);
-  const isPost = method === "POST" && !!request_body;
+  const includeBody = (method === "POST" || method === "PUT") && !!request_body;
   const authHeader = auth
     ? await auth.getAuthHeader(url.href, method)
     : undefined;
@@ -92,14 +92,14 @@ export async function request({
     url.toString(),
     {
       headers: {
-        ...(isPost
+        ...(includeBody
           ? { "Content-Type": "application/json; charset=utf-8" }
           : undefined),
         ...authHeader,
         ...headers,
       },
       method,
-      body: isPost ? JSON.stringify(request_body) : undefined,
+      body: includeBody ? JSON.stringify(request_body) : undefined,
       // Timeout if you don't see any data for 60 seconds
       // https://developer.twitter.com/en/docs/tutorials/consuming-streaming-data
       timeout: 60000,