Skip to content

Commit 6e973ad

Browse files
Christophe Gachiniardrefarer
Christophe Gachiniard
authored andcommitted
request body for PUT calls
1 parent cffcbdf commit 6e973ad

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

src/request.ts

+3-3
Original file line numberDiff line numberDiff line change
@@ -84,22 +84,22 @@ export async function request({
8484
}: RequestOptions): Promise<Response> {
8585
const url = new URL(base_url + endpoint);
8686
url.search = buildQueryString(query);
87-
const isPost = method === "POST" && !!request_body;
87+
const includeBody = (method === "POST" || method === "PUT") && !!request_body;
8888
const authHeader = auth
8989
? await auth.getAuthHeader(url.href, method)
9090
: undefined;
9191
const response = await fetchWithRetries(
9292
url.toString(),
9393
{
9494
headers: {
95-
...(isPost
95+
...(includeBody
9696
? { "Content-Type": "application/json; charset=utf-8" }
9797
: undefined),
9898
...authHeader,
9999
...headers,
100100
},
101101
method,
102-
body: isPost ? JSON.stringify(request_body) : undefined,
102+
body: includeBody ? JSON.stringify(request_body) : undefined,
103103
// Timeout if you don't see any data for 60 seconds
104104
// https://developer.twitter.com/en/docs/tutorials/consuming-streaming-data
105105
timeout: 60000,

0 commit comments

Comments
 (0)