From e5fbd92fafbb85d9cc094a860ec0f8dbc8ae5775 Mon Sep 17 00:00:00 2001 From: fraxken Date: Thu, 30 Oct 2025 14:27:56 +0100 Subject: [PATCH] chore: implement undici options for blocking pipelining --- src/request.ts | 15 ++++++++++++++- src/stream.ts | 6 +++++- 2 files changed, 19 insertions(+), 2 deletions(-) diff --git a/src/request.ts b/src/request.ts index 4ef9d8a..719d987 100644 --- a/src/request.ts +++ b/src/request.ts @@ -39,6 +39,13 @@ export interface RequestOptions { querystring?: string | URLSearchParams; body?: any; authorization?: string; + /** + * Whether the response is expected to take a long time and would end up blocking the pipeline. + * When this is set to true further pipelining will be avoided on the same connection until headershave been received. + * + * Defaults to method !== 'HEAD'. + */ + blocking?: boolean; // Could be dynamically computed depending on the provided URI. agent?: undici.Agent | undici.ProxyAgent | undici.MockAgent; /** @description API limiter from a package like `p-ratelimit`. */ @@ -83,7 +90,13 @@ export async function request( const headers = Utils.createHeaders({ headers: options.headers, authorization: options.authorization }); const body = Utils.createBody(options.body, headers); - const requestOptions = { method: method as HttpMethod, headers, body, dispatcher }; + const requestOptions = { + method: method as HttpMethod, + headers, + body, + dispatcher, + blocking: options.blocking + }; const requestResponse = limit === null ? await undici.request(computedURI.url, requestOptions) : await limit(() => undici.request(computedURI.url, requestOptions)); diff --git a/src/stream.ts b/src/stream.ts index 030b39e..7d5cbb2 100644 --- a/src/stream.ts +++ b/src/stream.ts @@ -33,7 +33,11 @@ export function pipeline( const body = Utils.createBody(options.body, headers); return undici.pipeline(computedURI.url, { - method: method as HttpMethod, headers, body, dispatcher + method: method as HttpMethod, + headers, + body, + dispatcher, + blocking: options.blocking }, ({ body }) => body); }