How nodejs/undici works
Undici is a Node.js HTTP client with both low-level dispatch APIs and Web-compatible Fetch APIs. A typical request enters through the exported API, is dispatched through a client/connection pool, and is encoded and parsed by an HTTP protocol implementation before a response reaches the caller. The repository also provides pooling and proxy options, middleware-like interceptors, caching, and Web APIs such as Fetch, WebSocket, and EventSource. Several capability links are documented rather than verified from sampled implementation files.
Main entry points: index.js Undici exports · client.js Dispatcher · cache.js Cache interceptor · client-h1.js HTTP/1 client
Components 20
Public interfaces
- Undici exports
index.js - Request APIs
lib/api
Dispatch and transport
- Dispatcher
lib/dispatcher/client.js - Request state
lib/core/request.js - Connection pools
lib/dispatcher/pool.js - HTTP/1 client
lib/dispatcher/client-h1.js - HTTP/2 client
lib/dispatcher/client-h2.js - HTTP/1 parser
lib/llhttp/llhttp-wasm.js
Interceptors and cache
- Interceptors
lib/interceptor - Cache interceptor
lib/interceptor/cache.js - Cache handler
lib/handler/cache-handler.js - Memory cache
lib/cache/memory-cache-store.js - SQLite cache
lib/cache/sqlite-cache-store.js
Web APIs
- Fetch API
lib/web/fetch/index.js - WebSocket
lib/web/websocket/websocket.js - EventSource
lib/web/eventsource/eventsource.js - Cookies
lib/web/cookies/index.js - Cache Storage
lib/web/cache/cachestorage.js
Other components
- Application
- HTTP service
Connections 23
- Application → Undici exports: uses
README.md - Undici exports → Request APIs: exports
index.js - Undici exports → Dispatcher: exports
index.js - Application → Fetch API: calls
README.md - Request APIs → Dispatcher: dispatches
- Fetch API → Dispatcher: dispatches
- Dispatcher → Request state: creates
lib/dispatcher/client.js - Dispatcher → HTTP/1 client: uses
lib/dispatcher/client.js - Dispatcher → HTTP/2 client: uses
lib/dispatcher/client.js - Connection pools → Dispatcher: manages
- HTTP/1 client → HTTP/1 parser: parses with
lib/dispatcher/client-h1.js - HTTP/1 client → HTTP service: sends HTTP
- HTTP/2 client → HTTP service: sends HTTP/2
- Undici exports → Interceptors: exports
index.js - Interceptors → Cache interceptor: includes
index.js - Cache interceptor → Cache handler: uses
lib/interceptor/cache.js - Cache interceptor → Memory cache: defaults to
lib/interceptor/cache.js - Cache interceptor → SQLite cache: supports
- Cache handler → Memory cache: reads and writes
lib/handler/cache-handler.js - Undici exports → WebSocket: exports
- Undici exports → EventSource: exports
- Undici exports → Cookies: exports
index.js - Undici exports → Cache Storage: exports
index.js