CodeVetter · Repo Unpack · Extension points
sindresorhus/got
Extension is primarily instance composition and callback-based customization. Handler middleware wraps the request interface, while lifecycle hooks operate at specific normalization and transport stages. Request functions, connection factories, agents, cookie jars, and cache adapters substitute infrastructure without replacing the public client. Pagination and JSON callbacks customize data interpretation and follow-up behavior.
- got.extend(...instancesOrOptions) merges option histories, concatenates handlers, carries mutableDefaults settings, and calls create() to produce a new instance.
- HandlerFunction receives Options and next(options); iterateHandlers dispatches them in order and preserves Promise helper descriptors on wrapped results. Stream handlers must return synchronously according to the instance documentation.
- Hook registration accepts only recognized hook events and function arrays; merging appends hooks, and init hooks can consume custom raw options into context before unknown-option validation.
- The request option can supply a custom request/response synchronously or asynchronously; undefined results fall back to the built-in transport. A beforeRequest hook can short-circuit later hooks by returning a request or response.
- Transport customization uses protocol-specific agents, createConnection, dnsLookup/dnsCache, and h2session; stable wrapped DNS lookup identity is deliberately maintained for HTTP/2 session reuse.
- Cache storage accepts Map-like adapters, with QuickLRU TTL translation; beforeCache hooks synchronously mutate cache metadata or return false to prevent storage, and Promise returns are rejected.
- Pagination customization replaces transform, filter, shouldContinue, and paginate callbacks; paginate can stop with false or supply updated options, and returned pagination settings affect subsequent iterations.
- parseJson/stringifyJson replace JSON codecs; cookieJar implements getCookieString/setCookie, with legacy callback jars promisified; diagnostics subscribers consume typed lifecycle messages through Node channels.