Skip to content

Preserve endpointFetch response headers - #2848

Open
akalinin-stripe wants to merge 1 commit into
masterfrom
preserve-endpoint-fetch-response-headers
Open

akalinin-stripe wants to merge 1 commit into
masterfrom
preserve-endpoint-fetch-response-headers

Conversation

@akalinin-stripe

Copy link
Copy Markdown
Contributor

Why?

EndpointFetchHttpClient currently replaces response headers with an empty object. This prevents response metadata and retry signals returned by endpointFetch from reaching stripe-node responses and errors.

What?

  • Preserve optional response headers from successful endpointFetch calls.
  • Preserve optional response headers from response-shaped rejections.
  • Keep the existing empty-header behavior when the runtime omits headers.
  • Add coverage for SDK response headers and retry-after on Stripe API errors.

Test Plan

  • tsc -p tsconfig.cjs.json --pretty false
  • mocha test/net/EndpointFetchHttpClient.spec.ts test/ExtensibilityPlatformFunctions.spec.ts
  • Targeted ESLint and Prettier checks for changed files

Changelog

  • Preserves response headers returned by endpointFetch in extensibility runtimes.

Committed-By-Agent: codex
Co-authored-by: codex <[email protected]>
@akalinin-stripe
akalinin-stripe requested a review from a team as a code owner September 11, 2026 18:07
@akalinin-stripe
akalinin-stripe requested review from kidus-stripe and removed request for a team September 11, 2026 18:07

@ratomirjovanovic ratomirjovanovic left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Small, focused change, and passing these through is useful. Two notes.

The changelog line mentions retry signals. stripe-should-retry is now honored for endpointFetch responses, since _shouldRetry reads it from getHeaders(), but retry-after only reaches error.headers: _getSleepTimeInMS does not read it, so it does not change the backoff. Worth wording the changelog so nobody expects the delay to follow retry-after.


constructor(res: EndpointFetchResponse) {
super(res.status, {});
super(res.status, res.headers ?? {});

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

RequestSender looks these up by lowercase key (request-id, stripe-should-retry, stripe-account, idempotency-key, stripe-notice). The other clients get lowercase names for free: Node's http lowercases them, and FetchHttpClient builds the object from a Headers instance. Here res.headers is a plain record, so if the runtime ever returns Request-Id or Stripe-Should-Retry, every lookup misses without an error. Lowercasing the keys once here (and for the rejection path on line 124) would make that independent of the runtime, and a test with mixed-case names would pin it.

@kidus-stripe
kidus-stripe requested review from a team and mark-kogan-stripe and removed request for a team and kidus-stripe October 26, 2026 18:35

This branch has not been deployed

No deployments
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants