Skip to content

feat(storage): extract shared header normalization utility - #2251

Merged
mandarini merged 3 commits into
masterfrom
feat/storage-header-util
Apr 17, 2026
Merged

mandarini merged 3 commits into
masterfrom
feat/storage-header-util

Conversation

@mandarini

@mandarini mandarini commented Apr 15, 2026 •

Copy link
Copy Markdown
Contributor

Description

What changed?

Extracted a reusable setHeader() utility in storage-js that performs case-insensitive header deduplication. This consolidates header normalization logic that was previously scattered across multiple files:

  • New file: headers.ts - Exports setHeader(headers, name, value) which removes any existing header matching the name (case-insensitive) before setting the new value. Returns a new object without mutating the input.
  • fetch.ts - Removed the private setRequestHeader function and replaced it with the shared setHeader import.
  • BaseApiClient.ts - The setHeader method now delegates to the utility instead of inline lowercasing.
  • StorageFileApi.ts - User-provided fileOptions.headers are now merged via setHeader in a loop instead of a raw object spread, preventing case-variant duplicates (e.g. a user passing Content-Type when content-type already exists).

Why was this change needed?

PR #2211 lowercased all headers in the BaseApiClient constructor. PR #2220 fixed the resulting Content-Type / content-type duplicate in _getRequestParams with inline logic.

The utility is scoped to storage-js for now since other packages (postgrest-js, supabase-js) already use the native Headers API which handles case-insensitivity natively.

Breaking changes

  • This PR contains no breaking changes

Checklist

  • I have read the Contributing Guidelines
  • My PR title follows the conventional commit format: <type>(<scope>): <description>
  • I have run npx nx format to ensure consistent code formatting
  • I have added tests for new functionality (if applicable)
  • I have updated documentation (if applicable)

Additional notes

@mandarini
mandarini requested review from a team as code owners April 15, 2026 10:45
@github-actions github-actions Bot added the storage-js Related to the storage-js library. label Apr 15, 2026
@pkg-pr-new

pkg-pr-new Bot commented Apr 15, 2026 •

Copy link
Copy Markdown

Open in StackBlitz

@supabase/auth-js

npm i https://pkg.pr.new/@supabase/auth-js@2251

@supabase/functions-js

npm i https://pkg.pr.new/@supabase/functions-js@2251

@supabase/postgrest-js

npm i https://pkg.pr.new/@supabase/postgrest-js@2251

@supabase/realtime-js

npm i https://pkg.pr.new/@supabase/realtime-js@2251

@supabase/storage-js

npm i https://pkg.pr.new/@supabase/storage-js@2251

@supabase/supabase-js

npm i https://pkg.pr.new/@supabase/supabase-js@2251

commit: 1798eac

@mandarini
mandarini force-pushed the feat/storage-header-util branch from 1481ef3 to bb4e17a Compare April 15, 2026 12:58
@mandarini
mandarini requested a review from ferhatelmas April 15, 2026 12:59
@mandarini
mandarini force-pushed the feat/storage-header-util branch from bb4e17a to dac0ac2 Compare April 16, 2026 13:06
@mandarini
mandarini requested a review from ferhatelmas April 16, 2026 13:07
@mandarini
mandarini force-pushed the feat/storage-header-util branch from dac0ac2 to 1798eac Compare April 16, 2026 13:18
@mandarini
mandarini merged commit b72a724 into master Apr 17, 2026
24 checks passed
@mandarini
mandarini deleted the feat/storage-header-util branch April 17, 2026 10:57
mandarini pushed a commit to supabase/ssr that referenced this pull request Apr 20, 2026
This PR updates `@supabase/supabase-js` to v2.104.0.

**Source**: supabase-js-stable-release

---

## Release Notes

## v2.104.0

## 2.104.0 (2026-04-20)

### 🚀 Features

- **storage:** extract shared header normalization utility
([#2251](supabase/supabase-js#2251))

### ❤️ Thank You

- Katerina Skroumpelou @mandarini
## v2.103.3

## 2.103.3 (2026-04-16)

### 🩹 Fixes

- **realtime:** throw Error objects instead of bare strings
([#2256](supabase/supabase-js#2256))
- **storage:** correct signedUrl type to allow null in createSignedUrls
([#2254](supabase/supabase-js#2254))

### ❤️ Thank You

- Katerina Skroumpelou @mandarini
- oniani1

This PR was created automatically.

Co-authored-by: supabase-workflow-trigger[bot] <266661614+supabase-workflow-trigger[bot]@users.noreply.github.com>
mandarini pushed a commit to supabase/supabase that referenced this pull request Apr 20, 2026
This PR updates @supabase/*-js libraries to version 2.104.0.

**Source**: supabase-js-stable-release

**Changes**:
- Updated @supabase/supabase-js to 2.104.0
- Updated @supabase/auth-js to 2.104.0
- Updated @supabase/realtime-js to 2.104.0
- Updated @supabase/postgest-js to 2.104.0
- Refreshed pnpm-lock.yaml

---

## Release Notes

## v2.104.0

## 2.104.0 (2026-04-20)

### 🚀 Features

- **storage:** extract shared header normalization utility
([#2251](supabase/supabase-js#2251))

### ❤️ Thank You

- Katerina Skroumpelou @mandarini
## v2.103.3

## 2.103.3 (2026-04-16)

### 🩹 Fixes

- **realtime:** throw Error objects instead of bare strings
([#2256](supabase/supabase-js#2256))
- **storage:** correct signedUrl type to allow null in createSignedUrls
([#2254](supabase/supabase-js#2254))

### ❤️ Thank You

- Katerina Skroumpelou @mandarini
- oniani1

This PR was created automatically.

Co-authored-by: supabase-workflow-trigger[bot] <266661614+supabase-workflow-trigger[bot]@users.noreply.github.com>
spydon added a commit to supabase/supabase-py that referenced this pull request Nov 3, 2026
## What kind of change does this PR introduce?

Bug fix. Closes #1941.

## What is the current behavior?

`_request` merges the client's headers into the per-call headers last,
in a plain dict, so header names are compared case-sensitively. An
upload header named `Authorization` is sent next to the client's
`authorization`, and one named `authorization` is replaced by the
client's value.

## What is the new behavior?

`_request` now starts from the client's headers in an `httpx.Headers`
and sets each per-call header on top, so a per-call header replaces the
client's header of the same name in any casing. This applies to
`upload`, `update` and `upload_to_signed_url`, matching
supabase/supabase-js#2251. The other callers of `_request` only pass
headers the client does not send (`x-upsert`, `Content-Type`), so they
are unaffected.


<!-- This is an auto-generated comment: release notes by coderabbit.ai
-->
<!-- coderabbit-ai-generated:v1 -->

## Summary by CodeRabbit

* **Bug Fixes**
* Per-request headers now take precedence over client defaults for
uploads, updates, and signed-URL uploads. Client headers take precedence
over matching HTTP-client headers, while HTTP-client-only headers are
retained. Client defaults are still sent when no per-request headers are
supplied.
* **Tests**
* Added coverage for header precedence and retention across synchronous
and asynchronous clients, including upload, update, and signed-URL
upload requests.
<!-- end of auto-generated comment: release notes by coderabbit.ai -->

---------

Co-authored-by: Lukas Klingsbo <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

storage-js Related to the storage-js library.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants