From 6f82ec0d7e6df9402c8ba336ba7a8090bcb4ca23 Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Thu, 30 Jul 2026 12:14:59 -0400 Subject: [PATCH 1/2] Add optional cacheControl to put and bump to 0.2.0 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Consumers migrating hosts that serve stored images publicly need to keep a Cache-Control header with the object (first recorded need: Exsimplify product image uploads storing "public, max-age=31536000, immutable"). Every first-class backend keeps Cache-Control as native object state served with the bytes — Azure blobHTTPHeaders.blobCacheControl, S3 and R2 CacheControl — so it is an honest intersection, unlike signed URLs or lifecycle rules, which stay out of the port. PutOptions gains an optional cacheControl validated like content-type (printable ASCII, no surrounding whitespace, 256-byte cap, no default); BlobObjectInfo returns it from head/get, undefined when a put omitted it, and a replacing put without one clears it. Conformance covers round-trip, absent-by-default, replace-clears, and rejection across the memory store and all three adapters. Minor bump to 0.2.0 since the port surface grew. Co-Authored-By: Claude Fable 5 --- README.md | 10 ++-- docs/PROJECT_PLAN.md | 8 ++- package-lock.json | 14 ++--- packages/storage-azure-blob/README.md | 2 +- packages/storage-azure-blob/package.json | 4 +- packages/storage-azure-blob/src/index.ts | 21 ++++++- packages/storage-blobs/README.md | 15 ++++- packages/storage-blobs/package.json | 2 +- packages/storage-blobs/src/conformance.ts | 65 +++++++++++++++++++++ packages/storage-blobs/src/index.ts | 44 +++++++++++++- packages/storage-cloudflare-r2/README.md | 2 +- packages/storage-cloudflare-r2/package.json | 4 +- packages/storage-cloudflare-r2/src/index.ts | 17 ++++++ packages/storage-s3/README.md | 2 +- packages/storage-s3/package.json | 4 +- packages/storage-s3/src/index.ts | 17 ++++++ 16 files changed, 202 insertions(+), 29 deletions(-) diff --git a/README.md b/README.md index ee203da..962b3d1 100644 --- a/README.md +++ b/README.md @@ -7,7 +7,7 @@ Object (blob) storage for [Pegma](https://pegma.dev) components — the byte counterpart to structured records in `@pegma/storage-core`. > [!IMPORTANT] -> Storage Blobs is early `0.x`. Packages are published at `0.1.0`; pin exact +> Storage Blobs is early `0.x`. Packages are published at `0.2.0`; pin exact > versions. The public API is not frozen. ## Why it exists @@ -27,10 +27,10 @@ application path. | Package | Role | Status | | ------------------------------ | ------------------------------------- | ----------- | -| `@pegma/storage-blobs` | Port, memory store, conformance suite | `0.1.0` npm | -| `@pegma/storage-azure-blob` | Azure Blob Storage adapter | `0.1.0` npm | -| `@pegma/storage-cloudflare-r2` | Cloudflare R2 adapter | `0.1.0` npm | -| `@pegma/storage-s3` | AWS S3 / S3-compatible adapter | `0.1.0` npm | +| `@pegma/storage-blobs` | Port, memory store, conformance suite | `0.2.0` npm | +| `@pegma/storage-azure-blob` | Azure Blob Storage adapter | `0.2.0` npm | +| `@pegma/storage-cloudflare-r2` | Cloudflare R2 adapter | `0.2.0` npm | +| `@pegma/storage-s3` | AWS S3 / S3-compatible adapter | `0.2.0` npm | ## Constraint that shapes everything diff --git a/docs/PROJECT_PLAN.md b/docs/PROJECT_PLAN.md index ce5d056..313378b 100644 --- a/docs/PROJECT_PLAN.md +++ b/docs/PROJECT_PLAN.md @@ -2,9 +2,11 @@ ## Status -**Stage:** Phase 6 complete. `@pegma/storage-blobs@0.1.2` and the Azure Blob, -Cloudflare R2, and S3 adapters are on npm at the same version with -trusted-publisher provenance from signed annotated release tags. +**Stage:** Phase 6 complete. `@pegma/storage-blobs@0.2.0` and the Azure Blob, +Cloudflare R2, and S3 adapters publish at the same version with +trusted-publisher provenance from signed annotated release tags. `0.2.0` adds +an optional `cacheControl` on put, stored as native object state by every +first-class backend and returned by `head`/`get`. **Package (first release):** `@pegma/storage-blobs@0.1.0` (with adapters `@pegma/storage-azure-blob`, `@pegma/storage-cloudflare-r2`, diff --git a/package-lock.json b/package-lock.json index bb239e3..cf6de62 100644 --- a/package-lock.json +++ b/package-lock.json @@ -6249,11 +6249,11 @@ }, "packages/storage-azure-blob": { "name": "@pegma/storage-azure-blob", - "version": "0.1.2", + "version": "0.2.0", "license": "MIT", "dependencies": { "@azure/storage-blob": "^12.29.1", - "@pegma/storage-blobs": "0.1.2" + "@pegma/storage-blobs": "0.2.0" }, "engines": { "node": ">=22" @@ -6261,7 +6261,7 @@ }, "packages/storage-blobs": { "name": "@pegma/storage-blobs", - "version": "0.1.2", + "version": "0.2.0", "license": "MIT", "engines": { "node": ">=22" @@ -6269,11 +6269,11 @@ }, "packages/storage-cloudflare-r2": { "name": "@pegma/storage-cloudflare-r2", - "version": "0.1.2", + "version": "0.2.0", "license": "MIT", "dependencies": { "@aws-sdk/client-s3": "^3.1097.0", - "@pegma/storage-blobs": "0.1.2" + "@pegma/storage-blobs": "0.2.0" }, "engines": { "node": ">=22" @@ -6281,11 +6281,11 @@ }, "packages/storage-s3": { "name": "@pegma/storage-s3", - "version": "0.1.2", + "version": "0.2.0", "license": "MIT", "dependencies": { "@aws-sdk/client-s3": "^3.1097.0", - "@pegma/storage-blobs": "0.1.2" + "@pegma/storage-blobs": "0.2.0" }, "engines": { "node": ">=22" diff --git a/packages/storage-azure-blob/README.md b/packages/storage-azure-blob/README.md index 4f827ae..a53c6a2 100644 --- a/packages/storage-azure-blob/README.md +++ b/packages/storage-azure-blob/README.md @@ -6,7 +6,7 @@ Azure Blob Storage adapter for [`@pegma/storage-blobs`](../storage-blobs). > [!IMPORTANT] -> Early `0.x` (`0.1.0` on npm). Pin exact versions. Verified against Azurite in +> Early `0.x` (`0.2.0` on npm). Pin exact versions. Verified against Azurite in > this monorepo's CI. ## Usage diff --git a/packages/storage-azure-blob/package.json b/packages/storage-azure-blob/package.json index 1c88b9d..9c0d35b 100644 --- a/packages/storage-azure-blob/package.json +++ b/packages/storage-azure-blob/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/storage-azure-blob", - "version": "0.1.2", + "version": "0.2.0", "description": "Azure Blob Storage adapter for @pegma/storage-blobs.", "license": "MIT", "type": "module", @@ -30,7 +30,7 @@ }, "dependencies": { "@azure/storage-blob": "^12.29.1", - "@pegma/storage-blobs": "0.1.2" + "@pegma/storage-blobs": "0.2.0" }, "scripts": { "build": "tsc -p tsconfig.json", diff --git a/packages/storage-azure-blob/src/index.ts b/packages/storage-azure-blob/src/index.ts index 0866f92..53bb380 100644 --- a/packages/storage-azure-blob/src/index.ts +++ b/packages/storage-azure-blob/src/index.ts @@ -12,6 +12,7 @@ import { DEFAULT_MAX_OBJECT_BYTES, assertValidBlobKey, assertValidBlobPrefix, + assertValidCacheControl, assertValidContentType, normalizeUserMetadata, type BlobGetResult, @@ -228,6 +229,7 @@ function toObjectInfo( props: { contentLength: number | undefined; contentType: string | undefined; + cacheControl: string | undefined; etag: string | undefined; metadata: Record | undefined; }, @@ -241,6 +243,11 @@ function toObjectInfo( key, size: props.contentLength ?? 0, contentType: props.contentType ?? DEFAULT_CONTENT_TYPE, + // Azurite reports a cleared cache-control as "" rather than absent. + cacheControl: + props.cacheControl === undefined || props.cacheControl.length === 0 + ? undefined + : props.cacheControl, etag: props.etag, userMetadata: metadataFromAzure(props.metadata), }; @@ -316,6 +323,10 @@ export function createAzureBlobStore( const contentType = assertValidContentType( putOptions?.contentType ?? DEFAULT_CONTENT_TYPE, ); + const cacheControl = + putOptions?.cacheControl === undefined + ? undefined + : assertValidCacheControl(putOptions.cacheControl); const userMetadata = normalizeUserMetadata(putOptions?.userMetadata); const limitBytes = assertMaxBytes(putOptions?.maxBytes, maxObjectBytes); const bytes = await readBody(body, limitBytes); @@ -332,12 +343,18 @@ export function createAzureBlobStore( try { const uploadOptions: { - blobHTTPHeaders: { blobContentType: string }; + blobHTTPHeaders: { + blobContentType: string; + blobCacheControl?: string; + }; metadata?: Record; conditions?: { ifNoneMatch: "*" } | { ifMatch: string }; } = { blobHTTPHeaders: { blobContentType: contentType }, }; + if (cacheControl !== undefined) { + uploadOptions.blobHTTPHeaders.blobCacheControl = cacheControl; + } if (Object.keys(userMetadata).length > 0) { uploadOptions.metadata = { ...userMetadata }; } @@ -409,6 +426,7 @@ export function createAzureBlobStore( const info = toObjectInfo(key, { contentLength: download.contentLength, contentType: download.contentType, + cacheControl: download.cacheControl, etag: download.etag, metadata: download.metadata, }); @@ -440,6 +458,7 @@ export function createAzureBlobStore( return toObjectInfo(key, { contentLength: props.contentLength, contentType: props.contentType, + cacheControl: props.cacheControl, etag: props.etag, metadata: props.metadata, }); diff --git a/packages/storage-blobs/README.md b/packages/storage-blobs/README.md index a79064f..f854d35 100644 --- a/packages/storage-blobs/README.md +++ b/packages/storage-blobs/README.md @@ -8,13 +8,13 @@ components: opaque keys, streaming put/get, conditional writes, bounded prefix listing, and a conformance suite that every adapter must pass. > [!IMPORTANT] -> Early `0.x` (`0.1.0` on npm). Pin exact versions; the public API is not frozen. +> Early `0.x` (`0.2.0` on npm). Pin exact versions; the public API is not frozen. > See [PROJECT_PLAN.md](../../docs/PROJECT_PLAN.md). ## Install ```sh -npm install @pegma/storage-blobs@0.1.0 +npm install @pegma/storage-blobs@0.2.0 ``` ## Server-side composition @@ -34,6 +34,7 @@ const blobs: BlobStore = createMemoryBlobStore({ const key = "support-desk/attachments/01JEXAMPLE"; const put = await blobs.put(key, requestBodyStream, { contentType: "application/pdf", + cacheControl: "public, max-age=31536000, immutable", // optional ifNoneMatch: "*", // create-only userMetadata: { ticket_id: "t_123" }, }); @@ -82,6 +83,16 @@ do { Listing is not a snapshot. Always delete with the etag you observed. +### Cache-control + +`put` accepts an optional `cacheControl` string stored with the object and +returned by `head`/`get` (`undefined` when the put omitted it; a replacing put +without one clears it). It is in the port because every first-class backend +keeps Cache-Control as native object state served with the bytes — unlike +signed URLs or lifecycle rules, which stay out. The store never interprets the +value; whether a host response honours or overrides it is host policy, like +`Content-Disposition`. + ## Conformance (v1 specification) The exported suite **is** the v1 contract. A behaviour not asserted there is diff --git a/packages/storage-blobs/package.json b/packages/storage-blobs/package.json index 39f8d20..16d7806 100644 --- a/packages/storage-blobs/package.json +++ b/packages/storage-blobs/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/storage-blobs", - "version": "0.1.2", + "version": "0.2.0", "description": "Provider-neutral object (blob) storage: opaque keys, streaming put/get, conditionals, and a conformance suite.", "license": "MIT", "type": "module", diff --git a/packages/storage-blobs/src/conformance.ts b/packages/storage-blobs/src/conformance.ts index 103f769..7c82463 100644 --- a/packages/storage-blobs/src/conformance.ts +++ b/packages/storage-blobs/src/conformance.ts @@ -6,6 +6,7 @@ import { DEFAULT_CONTENT_TYPE, MAX_BLOB_KEY_BYTES, MAX_BLOB_KEY_SEGMENTS, + MAX_CACHE_CONTROL_BYTES, MAX_LIST_PAGE_SIZE, MAX_USER_METADATA_TOTAL_BYTES, type BlobStore, @@ -745,6 +746,70 @@ export const conformanceCases: readonly ConformanceCase[] = [ assert.equal(await store.head("gone/obj"), null); assert.equal(await store.get("gone/obj"), null); }), + + // --- Cache-control (0.2.0 port extension) --- + + testCase( + "put stores cache-control and head/get return it verbatim", + async (store) => { + const cacheControl = "public, max-age=31536000, immutable"; + const put = await store.put("cache/asset.png", textBytes("png-bytes"), { + contentType: "image/png", + cacheControl, + }); + assert.equal(put.ok, true); + + const head = await store.head("cache/asset.png"); + assert.ok(head); + assert.equal(head.cacheControl, cacheControl); + + const got = await store.get("cache/asset.png"); + assert.ok(got); + assert.equal(got.cacheControl, cacheControl); + }, + ), + + testCase( + "head and get report undefined cache-control when a put omits one", + async (store) => { + await store.put("cache/plain", textBytes("x")); + const head = await store.head("cache/plain"); + assert.ok(head); + assert.equal(head.cacheControl, undefined); + const got = await store.get("cache/plain"); + assert.ok(got); + assert.equal(got.cacheControl, undefined); + }, + ), + + testCase( + "put replace clears cache-control when the replacing put omits it", + async (store) => { + await store.put("cache/replace", textBytes("v1"), { + cacheControl: "no-store", + }); + await store.put("cache/replace", textBytes("v2")); + const head = await store.head("cache/replace"); + assert.ok(head); + assert.equal(head.cacheControl, undefined); + }, + ), + + testCase("rejects illegal cache-control values", async (store) => { + const illegal = [ + "", + " no-store ", + "max-age=\u20ac", + "v".repeat(MAX_CACHE_CONTROL_BYTES + 1), + ]; + for (const cacheControl of illegal) { + await assert.rejects( + () => store.put("cache/bad", textBytes("x"), { cacheControl }), + (error: unknown) => error instanceof BlobValidationError, + ); + } + assert.equal(await store.head("cache/bad"), null); + }), ]; /** diff --git a/packages/storage-blobs/src/index.ts b/packages/storage-blobs/src/index.ts index ac013b0..7f9e05d 100644 --- a/packages/storage-blobs/src/index.ts +++ b/packages/storage-blobs/src/index.ts @@ -45,6 +45,9 @@ export const MAX_CONTENT_TYPE_BYTES = 256; /** Content-type applied when a put omits one. */ export const DEFAULT_CONTENT_TYPE = "application/octet-stream"; +/** Maximum UTF-8 byte length of a stored cache-control value. */ +export const MAX_CACHE_CONTROL_BYTES = 256; + /** Published package name. Stable for smoke and release inventory checks. */ export const storageBlobsPackageName = "@pegma/storage-blobs" as const; @@ -88,6 +91,12 @@ export interface BlobObjectInfo { readonly key: string; readonly size: number; readonly contentType: string; + /** + * Cache-control header value stored at put time, or undefined when the put + * omitted one. Stored and returned verbatim; this package does not + * interpret it. + */ + readonly cacheControl: string | undefined; readonly etag: string; readonly userMetadata: Readonly>; } @@ -129,6 +138,14 @@ export interface PutOptions { * to the host. */ readonly contentType?: string; + /** + * Cache-control header value to store with the object (for example + * `public, max-age=31536000, immutable`). No default; a replacing put + * without one clears any previously stored value. Stored because every + * first-class backend keeps it as native object state and serves it with + * the bytes; how responses are cached remains host policy. + */ + readonly cacheControl?: string; /** * Small string map stored with the object. Keys and values are constrained * so every first-class backend can round-trip them. @@ -170,7 +187,7 @@ export interface ListOptions { readonly cursor?: string; } -/** One object in a list page. Content-type is not listed (backend intersection). */ +/** One object in a list page. Content-type and cache-control are not listed (backend intersection). */ export interface BlobListEntry { readonly key: string; readonly size: number; @@ -248,6 +265,7 @@ export interface MemoryBlobStoreOptions { interface StoredBlob { readonly bytes: Uint8Array; readonly contentType: string; + readonly cacheControl: string | undefined; readonly etag: string; readonly userMetadata: Readonly>; } @@ -403,6 +421,24 @@ export function assertValidContentType(contentType: string): string { return contentType; } +/** Validates and returns a portable cache-control string. */ +export function assertValidCacheControl(cacheControl: string): string { + if (typeof cacheControl !== "string" || cacheControl.length === 0) { + throw new BlobValidationError("Cache-control must be a non-empty string."); + } + // Must be portable as an HTTP Cache-Control header across first-class backends. + if (!isPrintableAscii(cacheControl)) { + throw new BlobValidationError("Cache-control must be printable ASCII."); + } + assertNoSurroundingWhitespace(cacheControl, "Cache-control"); + if (utf8ByteLength(cacheControl) > MAX_CACHE_CONTROL_BYTES) { + throw new BlobValidationError( + `Cache-control exceeds ${MAX_CACHE_CONTROL_BYTES} UTF-8 bytes.`, + ); + } + return cacheControl; +} + /** * Portable user-metadata keys. Lowercase only: S3 lowercases metadata names, * so mixed-case keys are not an honest intersection. @@ -640,6 +676,7 @@ function toObjectInfo(key: string, stored: StoredBlob): BlobObjectInfo { key, size: stored.bytes.byteLength, contentType: stored.contentType, + cacheControl: stored.cacheControl, etag: stored.etag, userMetadata: stored.userMetadata, }; @@ -693,6 +730,10 @@ export function createMemoryBlobStore( const contentType = assertValidContentType( putOptions?.contentType ?? DEFAULT_CONTENT_TYPE, ); + const cacheControl = + putOptions?.cacheControl === undefined + ? undefined + : assertValidCacheControl(putOptions.cacheControl); const userMetadata = normalizeUserMetadata(putOptions?.userMetadata); const limitBytes = assertMaxBytes(putOptions?.maxBytes, maxObjectBytes); @@ -732,6 +773,7 @@ export function createMemoryBlobStore( objects.set(key, { bytes, contentType, + cacheControl, etag, userMetadata, }); diff --git a/packages/storage-cloudflare-r2/README.md b/packages/storage-cloudflare-r2/README.md index 5a8ede3..36b5deb 100644 --- a/packages/storage-cloudflare-r2/README.md +++ b/packages/storage-cloudflare-r2/README.md @@ -7,7 +7,7 @@ Cloudflare R2 adapter for [`@pegma/storage-blobs`](../storage-blobs), via R2's S3-compatible API. > [!IMPORTANT] -> Early `0.x` (`0.1.0` on npm). Pin exact versions. Verified in this monorepo's +> Early `0.x` (`0.2.0` on npm). Pin exact versions. Verified in this monorepo's > CI against LocalStack S3 (S3-compatible local harness). Point the same client > at a real R2 endpoint for production. diff --git a/packages/storage-cloudflare-r2/package.json b/packages/storage-cloudflare-r2/package.json index f3b3739..031fd75 100644 --- a/packages/storage-cloudflare-r2/package.json +++ b/packages/storage-cloudflare-r2/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/storage-cloudflare-r2", - "version": "0.1.2", + "version": "0.2.0", "description": "Cloudflare R2 adapter for @pegma/storage-blobs (S3-compatible API).", "license": "MIT", "type": "module", @@ -30,7 +30,7 @@ }, "dependencies": { "@aws-sdk/client-s3": "^3.1097.0", - "@pegma/storage-blobs": "0.1.2" + "@pegma/storage-blobs": "0.2.0" }, "scripts": { "build": "tsc -p tsconfig.json", diff --git a/packages/storage-cloudflare-r2/src/index.ts b/packages/storage-cloudflare-r2/src/index.ts index 738d25d..df349ec 100644 --- a/packages/storage-cloudflare-r2/src/index.ts +++ b/packages/storage-cloudflare-r2/src/index.ts @@ -15,6 +15,7 @@ import { DEFAULT_MAX_OBJECT_BYTES, assertValidBlobKey, assertValidBlobPrefix, + assertValidCacheControl, assertValidContentType, normalizeUserMetadata, type BlobListPage, @@ -297,6 +298,7 @@ function toObjectInfo( props: { contentLength: number | undefined; contentType: string | undefined; + cacheControl: string | undefined; etag: string | undefined; metadata: Record | undefined; }, @@ -305,6 +307,11 @@ function toObjectInfo( key, size: props.contentLength ?? 0, contentType: props.contentType ?? DEFAULT_CONTENT_TYPE, + // Some S3-compatible servers report a cleared cache-control as "". + cacheControl: + props.cacheControl === undefined || props.cacheControl.length === 0 + ? undefined + : props.cacheControl, etag: requireEtag(props.etag, key), userMetadata: metadataFromS3(props.metadata), }; @@ -397,6 +404,7 @@ export function createCloudflareR2BlobStore( return toObjectInfo(key, { contentLength: response.ContentLength, contentType: response.ContentType, + cacheControl: response.CacheControl, etag: response.ETag, metadata: response.Metadata, }); @@ -431,6 +439,10 @@ export function createCloudflareR2BlobStore( const contentType = assertValidContentType( putOptions?.contentType ?? DEFAULT_CONTENT_TYPE, ); + const cacheControl = + putOptions?.cacheControl === undefined + ? undefined + : assertValidCacheControl(putOptions.cacheControl); const userMetadata = normalizeUserMetadata(putOptions?.userMetadata); const limitBytes = assertMaxBytes(putOptions?.maxBytes, maxObjectBytes); const bytes = await readBody(body, limitBytes); @@ -440,6 +452,7 @@ export function createCloudflareR2BlobStore( Key: string; Body: Uint8Array; ContentType: string; + CacheControl?: string; Metadata?: Record; IfNoneMatch?: string; IfMatch?: string; @@ -449,6 +462,9 @@ export function createCloudflareR2BlobStore( Body: bytes, ContentType: contentType, }; + if (cacheControl !== undefined) { + input.CacheControl = cacheControl; + } if (Object.keys(userMetadata).length > 0) { input.Metadata = { ...userMetadata }; } @@ -575,6 +591,7 @@ export function createCloudflareR2BlobStore( const info = toObjectInfo(key, { contentLength: response.ContentLength, contentType: response.ContentType, + cacheControl: response.CacheControl, etag: response.ETag, metadata: response.Metadata, }); diff --git a/packages/storage-s3/README.md b/packages/storage-s3/README.md index f22b725..eab498e 100644 --- a/packages/storage-s3/README.md +++ b/packages/storage-s3/README.md @@ -6,7 +6,7 @@ AWS S3 / S3-compatible adapter for [`@pegma/storage-blobs`](../storage-blobs). > [!IMPORTANT] -> Early `0.x` (`0.1.0` on npm). Pin exact versions. Verified in this monorepo's +> Early `0.x` (`0.2.0` on npm). Pin exact versions. Verified in this monorepo's > CI against LocalStack S3. Point the same client at real AWS S3 for production. > Other S3-compatible products must pass the frozen conformance suite before > hosts rely on them (MinIO is not a CI-proven target for this package). diff --git a/packages/storage-s3/package.json b/packages/storage-s3/package.json index 7bea126..ad351c2 100644 --- a/packages/storage-s3/package.json +++ b/packages/storage-s3/package.json @@ -1,6 +1,6 @@ { "name": "@pegma/storage-s3", - "version": "0.1.2", + "version": "0.2.0", "description": "AWS S3 / S3-compatible adapter for @pegma/storage-blobs.", "license": "MIT", "type": "module", @@ -30,7 +30,7 @@ }, "dependencies": { "@aws-sdk/client-s3": "^3.1097.0", - "@pegma/storage-blobs": "0.1.2" + "@pegma/storage-blobs": "0.2.0" }, "scripts": { "build": "tsc -p tsconfig.json", diff --git a/packages/storage-s3/src/index.ts b/packages/storage-s3/src/index.ts index 17247c1..a6648ec 100644 --- a/packages/storage-s3/src/index.ts +++ b/packages/storage-s3/src/index.ts @@ -15,6 +15,7 @@ import { DEFAULT_MAX_OBJECT_BYTES, assertValidBlobKey, assertValidBlobPrefix, + assertValidCacheControl, assertValidContentType, normalizeUserMetadata, type BlobListPage, @@ -298,6 +299,7 @@ function toObjectInfo( props: { contentLength: number | undefined; contentType: string | undefined; + cacheControl: string | undefined; etag: string | undefined; metadata: Record | undefined; }, @@ -306,6 +308,11 @@ function toObjectInfo( key, size: props.contentLength ?? 0, contentType: props.contentType ?? DEFAULT_CONTENT_TYPE, + // Some S3-compatible servers report a cleared cache-control as "". + cacheControl: + props.cacheControl === undefined || props.cacheControl.length === 0 + ? undefined + : props.cacheControl, etag: requireEtag(props.etag, key), userMetadata: metadataFromS3(props.metadata), }; @@ -396,6 +403,7 @@ export function createS3BlobStore(options: S3BlobStoreOptions): BlobStore { return toObjectInfo(key, { contentLength: response.ContentLength, contentType: response.ContentType, + cacheControl: response.CacheControl, etag: response.ETag, metadata: response.Metadata, }); @@ -430,6 +438,10 @@ export function createS3BlobStore(options: S3BlobStoreOptions): BlobStore { const contentType = assertValidContentType( putOptions?.contentType ?? DEFAULT_CONTENT_TYPE, ); + const cacheControl = + putOptions?.cacheControl === undefined + ? undefined + : assertValidCacheControl(putOptions.cacheControl); const userMetadata = normalizeUserMetadata(putOptions?.userMetadata); const limitBytes = assertMaxBytes(putOptions?.maxBytes, maxObjectBytes); const bytes = await readBody(body, limitBytes); @@ -439,6 +451,7 @@ export function createS3BlobStore(options: S3BlobStoreOptions): BlobStore { Key: string; Body: Uint8Array; ContentType: string; + CacheControl?: string; Metadata?: Record; IfNoneMatch?: string; IfMatch?: string; @@ -448,6 +461,9 @@ export function createS3BlobStore(options: S3BlobStoreOptions): BlobStore { Body: bytes, ContentType: contentType, }; + if (cacheControl !== undefined) { + input.CacheControl = cacheControl; + } if (Object.keys(userMetadata).length > 0) { input.Metadata = { ...userMetadata }; } @@ -575,6 +591,7 @@ export function createS3BlobStore(options: S3BlobStoreOptions): BlobStore { const info = toObjectInfo(key, { contentLength: response.ContentLength, contentType: response.ContentType, + cacheControl: response.CacheControl, etag: response.ETag, metadata: response.Metadata, }); From c1fe5fe67a6557d81d636e0f175a436420365564 Mon Sep 17 00:00:00 2001 From: Nathan Rover Date: Thu, 30 Jul 2026 12:21:07 -0400 Subject: [PATCH 2/2] Assert get also clears cache-control after replacement Adapters read head and get through different provider calls, so the replace-clears case must pin both consumer-visible paths. Co-Authored-By: Claude Fable 5 --- packages/storage-blobs/src/conformance.ts | 3 +++ 1 file changed, 3 insertions(+) diff --git a/packages/storage-blobs/src/conformance.ts b/packages/storage-blobs/src/conformance.ts index 7c82463..f9a166d 100644 --- a/packages/storage-blobs/src/conformance.ts +++ b/packages/storage-blobs/src/conformance.ts @@ -792,6 +792,9 @@ export const conformanceCases: readonly ConformanceCase[] = [ const head = await store.head("cache/replace"); assert.ok(head); assert.equal(head.cacheControl, undefined); + const got = await store.get("cache/replace"); + assert.ok(got); + assert.equal(got.cacheControl, undefined); }, ),