Skip to content

Commit

Permalink
fix: disable h1 keep-alive by default
Browse files Browse the repository at this point in the history
  • Loading branch information
stefan-guggisberg committed Apr 10, 2024
1 parent 6fc1baf commit 74c63eb
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 12 deletions.
25 changes: 17 additions & 8 deletions src/fetch/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -442,40 +442,49 @@ class FetchContext {
noCache: (options = {}) => new FetchContext({ ...options, maxCacheSize: 0 }).api(),

/**
* Convenience function which creates a new context with enforced HTTP/1.1 protocol,
* the equivalent of `context({ alpnProtocols: [ALPN_HTTP1_1] })`.
* Convenience function which creates a new context with enforced HTTP/1.1 protocol
* and disabled persistent connections (keep-alive), the equivalent of
* `context({ alpnProtocols: [ALPN_HTTP1_1], h1: { keepAlive: false } })`.
*
* The optional `options` parameter allows to specify further options.
*
* @param {Object} [options={}]
*/
h1: (options = {}) => new FetchContext({
...options, alpnProtocols: [this.context.ALPN_HTTP1_1],
...options,
alpnProtocols: [this.context.ALPN_HTTP1_1],
h1: { keepAlive: false },
}).api(),

/**
* Convenience function which creates a new context with enforced HTTP/1.1 protocol
* and persistent connections (keep-alive), the equivalent of
* with persistent connections (keep-alive), the equivalent of
* `context({ alpnProtocols: [ALPN_HTTP1_1], h1: { keepAlive: true } })`.
*
* The optional `options` parameter allows to specify further options.
*
* @param {Object} [options={}]
*/
keepAlive: (options = {}) => new FetchContext({
...options, alpnProtocols: [this.context.ALPN_HTTP1_1], h1: { keepAlive: true },
...options,
alpnProtocols: [this.context.ALPN_HTTP1_1],
h1: { keepAlive: true },
}).api(),

/**
* Convenience function which creates a new context with disabled caching
* and enforced HTTP/1.1 protocol, a combination of `h1()` and `noCache()`.
* Convenience function which creates a new context with disabled caching,
* enforced HTTP/1.1 protocol and disabled persistent connections (keep-alive),
* a combination of `h1()` and `noCache()`.
*
* The optional `options` parameter allows to specify further options.
*
* @param {Object} [options={}]
*/
h1NoCache: (options = {}) => new FetchContext({
...options, maxCacheSize: 0, alpnProtocols: [this.context.ALPN_HTTP1_1],
...options,
maxCacheSize: 0,
alpnProtocols: [this.context.ALPN_HTTP1_1],
h1: { keepAlive: false },
}).api(),

/**
Expand Down
10 changes: 6 additions & 4 deletions src/index.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,9 @@ export declare function context(options?: ContextOptions): FetchAPI;
export declare function noCache(options?: ContextOptions): FetchAPI;

/**
* Convenience function which creates a new context with enforced HTTP/1.1 protocol,
* the equivalent of `context({ alpnProtocols: [ALPN_HTTP1_1] })`.
* Convenience function which creates a new context with enforced HTTP/1.1 protocol
* and disabled persistent connections (keep-alive), the equivalent of
* `context({ alpnProtocols: [ALPN_HTTP1_1], h1: { keepAlive: false } })`.
*
* The optional `options` parameter allows to specify further options.
*
Expand All @@ -57,8 +58,9 @@ export declare function noCache(options?: ContextOptions): FetchAPI;
export declare function keepAlive(options?: ContextOptions): FetchAPI;

/**
* Convenience function which creates a new context with disabled caching
* and enforced HTTP/1.1 protocol, a combination of `h1()` and `noCache()`.
* Convenience function which creates a new context with disabled caching,
* and enforced HTTP/1.1 protocol with disabled persistent connections (keep-alive),
* a combination of `h1()` and `noCache()`.
*
* The optional `options` parameter allows to specify further options.
*
Expand Down

0 comments on commit 74c63eb

Please sign in to comment.