# Behavior traces — sindresorhus/got

> Canonical page: https://codevetter.com/unpack/got/behavior-traces

# Behavior traces — sindresorhus/got

Scanned commit e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4 (2026-09-20). Generated by codevetter codevetter 1.15.0 on 2026-10-02.

Source inspection; upstream code and tests were not executed.

Eight source walks cover instance initialization and the main user-visible execution paths. The Promise and stream paths share normalization and transport setup but differ in upload completion and response buffering. Redirect and retry paths preserve or replace request state under distinct rules. Cache reuse, cookie persistence, and pagination reconnect retained state to later requests.
- Initialization: source/index.ts creates Options → create(defaults) clones options/handlers → attaches extend, pagination, stream, and method shortcuts → freezes defaults unless mutableDefaults → exports got. — [source/index.ts#L5-L13](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/index.ts#L5-L13) [source/create.ts#L48-L59](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/create.ts#L48-L59) [source/create.ts#L346-L378](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/create.ts#L346-L378)
- JSON POST: got.post() → makeRequest() → new Request/new Options → handler chain/lastHandler → flush() → _finalizeBody() serializes JSON → _makeRequest(); response buffering precedes parseBody() and afterResponse hooks, then .json() returns the parsed body. — [source/create.ts#L85-L118](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/create.ts#L85-L118) [source/core/index.ts#L451-L473](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L451-L473) [source/core/index.ts#L1000-L1008](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L1000-L1008) [source/as-promise/index.ts#L57-L100](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/as-promise/index.ts#L57-L100) [source/as-promise/index.ts#L288-L297](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/as-promise/index.ts#L288-L297)
- Stream upload: got.stream.post() → makeRequest(...,true) → Request.flush() → _onRequest() → _sendBody(); without a configured body, a payload-capable stream waits for caller writes/end, then response data is exposed through the Duplex. — [source/create.ts#L353-L362](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/create.ts#L353-L362) [source/core/index.ts#L1724-L1733](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L1724-L1733) [source/core/index.ts#L1862-L1877](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L1862-L1877) [source/core/index.ts#L1513-L1552](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L1513-L1552)
- Redirect: _onResponseBase() evaluates redirect policy → drains response → checks maxRedirects → clones Options/resolves Location → rewrites method/body and strips cross-origin state → runs beforeRedirect hooks → validates replayability → emits redirect and calls _makeRequest() again. — [source/core/index.ts#L1249-L1299](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L1249-L1299) [source/core/index.ts#L1301-L1339](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L1301-L1339) [source/core/index.ts#L1359-L1378](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L1359-L1378) [source/core/index.ts#L1445-L1481](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L1445-L1481)
- Retry: _beforeError() normalizes failure and Retry-After → calculateRetryDelay() and optional calculateDelay → backoff timer → beforeRetry hooks → cleanup/body preservation → retry event; asPromise() rejects an unchanged consumed body or constructs and flushes the next Request. — [source/core/index.ts#L494-L509](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L494-L509) [source/core/index.ts#L534-L609](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L534-L609) [source/core/index.ts#L625-L687](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L625-L687) [source/as-promise/index.ts#L209-L237](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/as-promise/index.ts#L209-L237)
- HTTP cache reuse: _makeRequest() selects eligible bodies → _prepareCache() creates/reuses a CacheableRequest wrapper → _createCacheableRequest() resolves a native request or cached ResponseLike → _onResponse() follows the normal response path and sets isFromCache; freshness/revalidation policy belongs to the dependency. — [source/core/index.ts#L2702-L2720](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L2702-L2720) [source/core/index.ts#L2174-L2179](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L2174-L2179) [source/core/index.ts#L2299-L2346](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L2299-L2346) [source/core/index.ts#L1073-L1079](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L1073-L1079) [documentation/cache.md#L5-L9](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/documentation/cache.md#L5-L9)
- Cookie persistence: _makeRequest() awaits getCookieString(URL) → sends generated Cookie unless omitted → _onResponseBase() writes each Set-Cookie sequentially → only then completes response/redirect handling; a later call consults the same caller-owned jar. — [source/core/index.ts#L2455-L2465](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L2455-L2465) [source/core/index.ts#L2502-L2507](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L2502-L2507) [source/core/index.ts#L1213-L1246](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/core/index.ts#L1213-L1246)
- Pagination: paginateEach() normalizes/validates callbacks → waits inter-page backoff → forces full-response resolution → calls got() → transform/filter/shouldContinue → yields items under limits → paginate() supplies follow-up options → applies cross-origin merge rules and refreshes pagination settings. — [source/create.ts#L194-L230](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/create.ts#L194-L230) [source/create.ts#L235-L275](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/create.ts#L235-L275) [source/create.ts#L277-L315](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/create.ts#L277-L315) [source/create.ts#L329-L342](https://github.com/sindresorhus/got/blob/e1d87d2ced01d5b7d855a7dc8b091bf7b014a1e4/source/create.ts#L329-L342)

Every claim links to its cited files at the pinned commit. Citations identify source evidence; they do not establish runtime correctness. Independent CodeVetter scan — not reviewed by upstream maintainers.

## Public product links

- [CodeVetter](https://codevetter.com/)
- [Download](https://codevetter.com/download)
- [Documentation](https://codevetter.com/docs/)
- [Source](https://github.com/Codevetter/codevetter)
