fetch-http2
Advanced tools
Comparing version
@@ -6,2 +6,3 @@ "use strict"; | ||
const node_http2_1 = require("node:http2"); | ||
const defaultPingInterval = 20000; | ||
async function _fetch(url, options) { | ||
@@ -12,3 +13,3 @@ // Construct url | ||
const client = _httpClient(origin, { | ||
keepAlive: options?.keepAlive ?? 5000 | ||
pingInterval: parsePingInterval(options?.keepAlive) | ||
}); | ||
@@ -53,5 +54,5 @@ // Build http request | ||
let timer; | ||
// Send a ping every 5s to keep client alive | ||
if (typeof options?.keepAlive === 'number') { | ||
timer = (0, node_timers_1.setInterval)(() => client.ping(noop), options.keepAlive).unref(); | ||
// Send a ping every to keep client alive | ||
if (options.pingInterval > 0) { | ||
timer = (0, node_timers_1.setInterval)(() => client.ping(noop), options.pingInterval).unref(); | ||
} | ||
@@ -103,1 +104,11 @@ // Create function to destroy client | ||
} | ||
function parsePingInterval(keepAlive) { | ||
switch (typeof keepAlive) { | ||
case 'number': | ||
return keepAlive; | ||
case 'boolean': | ||
return keepAlive ? defaultPingInterval : 0; | ||
case 'undefined': | ||
return defaultPingInterval; | ||
} | ||
} |
{ | ||
"name": "fetch-http2", | ||
"version": "1.0.3", | ||
"version": "1.0.4", | ||
"description": "Native http2 fetch implementation for Node.js", | ||
@@ -5,0 +5,0 @@ "author": "Andrew Barba <barba@hey.com>", |
8856
3.68%196
5.95%