Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: reduce keep alive threshold #1501

Merged
merged 1 commit into from
Oct 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 8 additions & 2 deletions src/request.ts
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,13 @@ export const SUPPORTS_REQUEST = !!XMLHttpRequest || !!fetch
const CONTENT_TYPE_PLAIN = 'text/plain'
const CONTENT_TYPE_JSON = 'application/json'
const CONTENT_TYPE_FORM = 'application/x-www-form-urlencoded'

const SIXTY_FOUR_KILOBYTES = 64 * 1024
/*
fetch will fail if we request keepalive with a body greater than 64kb
sets the threshold lower than that so that
any overhead doesn't push over the threshold after checking here
*/
const KEEP_ALIVE_THRESHOLD = SIXTY_FOUR_KILOBYTES * 0.8
type EncodedBody = {
contentType: string
body: string | BlobPart
Expand Down Expand Up @@ -147,7 +153,7 @@ const _fetch = (options: RequestOptions) => {
// so let's get the best of both worlds and only set keepalive for POST requests
// where the body is less than 64kb
// NB this is fetch keepalive and not http keepalive
keepalive: options.method === 'POST' && (estimatedSize || 0) < 64 * 1024,
keepalive: options.method === 'POST' && (estimatedSize || 0) < KEEP_ALIVE_THRESHOLD,
body,
signal: aborter?.signal,
})
Expand Down
Loading