This repository contains the following packages:
@zentrick/fetchprovides a Fetch like interface that transparently handles connection pooling and both h1 and h2 support.@zentrick/h2-alpnprovides an H2 implementation that transparently handles both http and https connections, and transparently handles H1 and H2 servers over https by doing ALPN negotiation. All of these scenarios are exposed as an API that matches the native Nodehttp2API.@zentrick/h2-poolprovides a pool management class that built on top of@zentrick/h2-pooled-session. It will manage a list of origins and maintain a maximum number of idle sessions across all origins. When that maximum is reached it will evict the oldest session.@zentrick/h2-pooled-sessionprovides an H2 implementation in which one session maps to multiple backend sessions, and manages stream allocation to these backend sessions by accounting for each individual session'smaxConcurrentStreams.@zentrick/h2-utilcontains a number of helper classes that deal with the proxying of H2 sessions and streams.@zentrick/tls-session-cacheprovides a helper class that deals with caching of TLS sessions for faster connection setup times. In the Node https agents, this is handled out of the box for you.
fetch can be used like a normal browser fetch:
const response = await fetch('https://www.google.com')
console.log(await response.text())h2-alpn and h2-pooled-session can be used independently or combined. To use
them together, you can do the following:
const { connect } = require('@zentrick/h2-pooled-session')
const session = connect(authority, {
createSession: require('@zentrick/h2-alpn').connect
})The same can be done to combine h2-alpn and h2-pool as follows:
const Pool = require(`@zentrick/h2-pool`)
const pool = new Pool({
keepAlive: true,
createSession: require('@zentrick/h2-alpn').connect
})