Skip to content

fix(storage): skip transforms for conditional image responses - #5205

Merged
dbarrosop merged 3 commits into
5183from
storage-skip-transform-cond
Oct 20, 2026
Merged

dbarrosop merged 3 commits into
5183from
storage-skip-transform-cond

Conversation

@dbarrosop

@dbarrosop dbarrosop commented Oct 19, 2026 •

Copy link
Copy Markdown
Member

Goal

Avoid decoding and transforming images when storage can answer a conditional request with a bodyless 304 or 412 response using metadata validators. Preserve GET downloads and their authorization errors, status normalization, source-body cleanup, and explicit transformation-option validation. For HEAD, avoid downloading or transforming an image when no content length will be returned. Conditional responses intentionally take precedence over image-decoding or transformation failures.

Type: Bug fix

Changes

  • Conditional GET responses — Evaluate metadata-based preconditions after the existing download and status-normalization steps but before image transformation. Regular and presigned GET requests skip transformation for 304 and 412 responses while retaining the source body for existing response cleanup; responses requiring image content continue through the transformer.
  • Conditional HEAD responses — Download and transform an image only when the conditional result is 200 and a transformed content length is needed. Explicit option validation still runs before this decision, so invalid width, height, blur, or format parameters continue to return 400.
  • Regression coverage — Exercise regular GET, presigned GET, and HEAD with ETag/date validators, corrupt and valid images, invalid transformation options, and source-body read/close tracking. Additional GET cases cover download-authorization precedence and full-versus-partial 206 status handling; successful transformations check PNG output, width, content length, and modification time.

Key files

  • services/storage/controller/get_file.go (+16/-13) — Conditional GET evaluation and transformation ordering.
  • services/storage/controller/get_file_metadata_headers.go (+3/-1) — HEAD download/transformation gating.
  • services/storage/controller/get_file_revalidation_test.go (+388/-0) — Endpoint-level regression tests and body-lifecycle observers.

Review issue: 001 — .nhost-code/review/PR_5183_COMMENT_001.md — ADDRESSED, ACCEPT
Work unit: PR_5183/RUN-9377675573041723356/WU-001

Resolution:
- Skip GET image transformations for 304/412 while retaining downloads,
  authentication errors, status normalization, and source-body cleanup.
- Skip HEAD downloads and transforms when no content length is needed.

Why:
- Metadata supplies every validator input; bodyless conditional responses
  do not need decoded images or transformed buffers.

Accepted trade-off:
- As approved, 304/412 can mask decoding or transformation errors. Explicit
  invalid options still return 400. GET downloads are deliberately retained.

Checks:
- `GIN_MODE=release go test -race ./services/storage/controller -count=1` — exit 0: passed; reviewed state unchanged.
- `golines --dry-run --base-formatter=gofumpt .` — exit 0: passed; reviewed state unchanged.
- `golangci-lint run ./...` — exit 0: 0 issues.
- `git diff --check` — exit 0: passed; reviewed state unchanged.
- `git diff --cached --check` — exit 0: passed; reviewed state unchanged.
@dbarrosop
dbarrosop added this pull request to stack #5206 October 19, 2026 15:08
Review issue: 001 — .nhost-code/review/PR_5205_COMMENT_001.md — ADDRESSED, ACCEPT
Work unit: PR_5205/RUN-2949609135643056153/WU-001

Resolution:
- HEAD 200 headers now describe the transformed representation: a JPEG requested as PNG returns `image/png` and `nhost.jpg.png`, alongside its transformed length. Tests check both headers through the registered HTTP handlers.

Why:
- Reusing GET's existing representation-name/MIME helper prevents the format mapping from drifting between GET and HEAD. It fixes HEAD metadata for supported preflight requests without changing how files are transformed or downloaded.

Decisions:
- The resolved filename and MIME type are passed as two private response-builder arguments, rather than overwriting the source metadata or adding a new struct. The existing conditional-response branches are kept as they are, and the helper consolidation reserved for the next work unit is not attempted.

Validation limit (operator-approved):
- Storage integration startup exited 2: Docker cannot pull minio/minio:RELEASE.2025-02-28T09-55-16Z (insufficient_scope). The operator waived this unavailable gate for both fixes; the integration check was not run.

Checks:
- `nix develop .#storage --command bash -c 'GIN_MODE=release go test -race ./services/storage/controller -count=1'` — exit 0: passed; staged state unchanged.
- `nix develop .#storage --command golines --dry-run --base-formatter=gofumpt .` — exit 0: passed; staged state unchanged.
- `nix develop .#storage --command golangci-lint run ./...` — exit 0: 0 issues; staged state unchanged.
- `git diff --check 9397e80 --` — exit 0: passed.
- `git diff --cached --check` — exit 0: passed.
Review issue: 002 — .nhost-code/review/PR_5205_COMMENT_002.md — ADDRESSED, ACCEPT
Work unit: PR_5205/RUN-2949609135643056153/WU-002

Resolution:
- Conditional-date and revalidation tests use one metadata fixture, mock/controller/router setup, and regular/presigned/HEAD request builder. Callers supply their original download bodies and errors; absent downloads still leave storage calls forbidden by gomock. Existing test cases and assertions are preserved, including the committed transformed HEAD-header regression coverage.

Why:
- One shared superset removes fixture, routing, signing-query, and mock-wiring drift without introducing another abstraction or changing production behavior.

Decisions:
- Keep the two test files separate and place shared helpers in `get_file_conditionals_test.go`. Extend the existing neutral handler name rather than retain a wrapper. Keep `PresignedURLsEnabled: true` from the conditional suite as the shared bucket fixture, eliminating the prior inconsistency; only presigned-URL generation reads that flag, so the revalidation suites' behavior is unchanged. Pass timestamps into the shared metadata builder so the precision regression remains explicit.

Review-plan variance:
- Code: None. Validation: the MinIO-backed storage integration gate was omitted under the operator-approved exception; full-repository format/lint and the complete controller race suite passed.

Checks (staged candidate; reviewed state unchanged):
- `nix develop .#storage --command bash -c 'GIN_MODE=release go test -race ./services/storage/controller -count=1'` — exit 0: passed.
- `nix develop .#storage --command golines --dry-run --base-formatter=gofumpt .` — exit 0: passed.
- `nix develop .#storage --command golangci-lint run ./...` — exit 0: 0 issues.
- `git diff --check 373cab0 --` — exit 0: passed.
- `git diff --cached --check` — exit 0: passed.
- Storage integration check — not run under operator waiver: pinned MinIO image pull denied (insufficient_scope: authorization failed).
@dbarrosop dbarrosop self-assigned this Oct 19, 2026
@dbarrosop
dbarrosop merged commit e88946e into main Oct 20, 2026
8 checks passed
@dbarrosop
dbarrosop deleted the storage-skip-transform-cond branch October 20, 2026 06:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants