Skip to content

Commit

Permalink
Merge pull request #1065 from JupiterOne/http-client-text-body
Browse files Browse the repository at this point in the history
http-client: add option to pass text body
  • Loading branch information
RonaldEAM authored Apr 24, 2024
2 parents 4a9d688 + 1690dc8 commit 2e384ee
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
10 changes: 9 additions & 1 deletion packages/integration-sdk-http-client/src/client.ts
Original file line number Diff line number Diff line change
Expand Up @@ -241,6 +241,8 @@ export abstract class BaseAPIClient {
}
(fmtBody as FormData).append(key, value);
});
} else if (bodyType === 'text' && typeof body === 'string') {
fmtBody = body;
} else {
fmtBody = JSON.stringify(body);
}
Expand All @@ -250,6 +252,7 @@ export abstract class BaseAPIClient {
headers: {
...(bodyType === 'json' && { 'Content-Type': 'application/json' }),
...(bodyType === 'form' && (fmtBody as FormData).getHeaders()),
...(bodyType === 'text' && { 'Content-Type': 'text/plain' }),
Accept: 'application/json',
...(authorize && this.authorizationHeaders),
...headers,
Expand Down Expand Up @@ -497,7 +500,12 @@ export abstract class BaseAPIClient {
this.rateLimitThrottling.rateLimitHeaders?.reset ?? 'ratelimit-reset';

this.logger.warn(
{ rateLimitLimit, rateLimitRemaining, timeToSleepInMs },
{
endpoint: response.url,
rateLimitLimit,
rateLimitRemaining,
timeToSleepInMs,
},
`Exceeded ${thresholdPercentage}% of rate limit. Sleeping until ${resetHeaderName}`,
);
await sleep(timeToSleepInMs);
Expand Down
4 changes: 2 additions & 2 deletions packages/integration-sdk-http-client/src/types.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ export type OptionalPromise<T> = T | Promise<T>;

export interface RequestOptions {
method?: 'GET' | 'POST';
body?: Record<string, unknown>;
bodyType?: 'json' | 'form';
body?: Record<string, unknown> | string;
bodyType?: 'json' | 'form' | 'text';
headers?: Record<string, string>;
authorize?: boolean;
bucketTokens?: number;
Expand Down

0 comments on commit 2e384ee

Please sign in to comment.