GeezerVisonThe World Wide Web, restored to 800 pixels of glory. |
| Home|About|Gaming cabinet|Archives|How it works|Starter sites |
GeezerVison is showing github.com — bug: `retry.fetch` strips headers set by HTTP client libraries · Issue #2490 · triggerdotdev/trigger.dev Open DescriptionProvide environment informationSystem: Describe the bugSummaryThe Environment
Expected BehaviorWhen using Actual BehaviorHeaders set by HTTP client libraries are stripped during retry attempts, causing requests to fail with missing headers. Reproduction Steps
import createClient from "openapi-fetch"; import { retry } from "@trigger.dev/sdk"; const client = createClient({ baseUrl: "https://api.example.com", headers: { "Authorization": "Bearer token", "Content-Type": "application/json", }, fetch: retry.fetch, // Using retry.fetch });
const result = await client.POST("/api/endpoint", { body: { data: "test" } });
Root Cause AnalysisLooking at the const response = await fetch(input, { ...init, headers: { ...init?.headers, // Only preserves ORIGINAL headers from init "x-retry-count": attemptCount.toString(), }, }); The retry mechanism only spreads WorkaroundWe had to create a custom fetch wrapper: const retryFetchWithHeaders = async ( input: RequestInfo | URL, init?: RequestInit ): Promise<Response> => { const headers = new Headers(init?.headers); // Ensure required headers are present if (!headers.has('Authorization')) { headers.set('Authorization', `Bearer ${API_TOKEN}`); } if (!headers.has('Content-Type')) { headers.set('Content-Type', 'application/json'); } // Convert Headers to plain object for retry.fetch const headersObj: Record<string, string> = {}; headers.forEach((value, key) => { headersObj[key] = value; }); return retry.fetch(input, { ...init, headers: headersObj, }); }; Suggested FixThe const response = await fetch(input, { ...init, headers: { ...Object.fromEntries(new Headers(init?.headers).entries()), "x-retry-count": attemptCount.toString(), }, }); Or better yet, use the Headers API properly to merge headers without losing any that were set by middleware. ImpactThis affects any HTTP client library that:
Additional ContextThis is particularly problematic for OpenAPI-based clients where type-safe headers and authentication are crucial for API functionality. The current behavior makes Reproduction repoIncluded in description To reproduceIncluded in description Additional informationNo response ActivityMetadataMetadataAssigneesLabelsNo labels TypeProjectsMilestoneRelationshipsDevelopmentIssue actions |
| You are visitor 01402503 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |