feat(storage): add setHeader method to BaseApiClient #2079
+60
−0
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
🔍 Description
What changed?
Added a
setHeader(name, value)method toBaseApiClientin storage-js. This allows setting per-request HTTP headers on any storage operation, matching the existing pattern in postgrest-js which was added in supabase/postgrest-js#550.The method creates a shallow copy of the headers object to avoid mutating shared state between instances (e.g. between
StorageClientandStorageFileApireturned byfrom()).Why was this change needed?
postgrest-js supports per-request header overrides via
setHeader, but storage-js has no equivalent. Setting headers for storage requests currently requires creating a new Supabase client, setting the header usingoptions.global.headers– not preferable when headers need to be set dynamically per request.This PR enables use cases like:
📸 Screenshots/Examples
🔄 Breaking changes
📋 Checklist
<type>(<scope>): <description>npx nx formatto ensure consistent code formatting📝 Additional notes
storage-js currently uses an object to store headers, whereas postgrest-js transitioned from an object to the standard
HeadersAPI ~8mo ago in supabase/postgrest-js#619. I chose to keep the change minimal, but I'd be happy to migrate toHeadersin this PR if you'd prefer.Summary by CodeRabbit
New Features
Tests
✏️ Tip: You can customize this high-level summary in your review settings.