fix(storage): add user-agent for non-browser downloads
Summary
Fixes storage download failures in Cloudflare Workers caused by missing User-Agent headers.
Problem
When downloading files using presigned URLs from Cloudflare Workers, CloudFront returned 403 Forbidden because the requests did not include a User-Agent header.
Browsers automatically manage their User-Agent headers, but non-browser environments such as Cloudflare Workers do not provide one by default.
Changes
- Added a default
User-Agent: insforge-sdkheader for non-browser environments. - Avoided manually setting the User-Agent header in browser environments.
- Preserved the existing direct and presigned download handling.
Testing
- Verified downloads in Cloudflare Workers.
- Added unit tests for non-browser and browser header behavior.
- Verified that Authorization headers are not forwarded to presigned URLs.
Related issue
Closes #161
Original issue: InsForge/InsForge#2131
![View with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/view-with-codesmith-dark-v3-3x.png)
![Autofix with [code]smith](https://pr-comments-assets.blacksmith.sh/codesmith/autofix-with-codesmith-dark-3x.png)
Need help on this PR? Tag @codesmith-bot with what you need.
Summary by cubic
Fixes storage downloads in non-browser environments like Cloudflare Workers, which returned 403 Forbidden because CloudFront rejected presigned URL requests without a User-Agent header. Non-browser environments now send a default User-Agent: insforge-sdk header, while browsers and browser workers are unchanged. Download failures now return an InsForgeError instead of succeeding with a null body, and Authorization headers are not forwarded to presigned URLs. Addresses the SDK-side cause of InsForge/InsForge#2131.
Summary by CodeRabbit
- Updates
- Downloads initiated outside a browser now include an SDK identifier in the request. Browser download requests remain unchanged.
- Download error responses, including forbidden responses, are reported as storage errors.