Skip to content

feat: S3-compliant 301 redirects for renamed accounts#124

Draft
alukach wants to merge 7 commits intomainfrom
feat/account-rename-redirects
Draft

feat: S3-compliant 301 redirects for renamed accounts#124
alukach wants to merge 7 commits intomainfrom
feat/account-rename-redirects

Conversation

@alukach
Copy link
Copy Markdown
Contributor

@alukach alukach commented Mar 30, 2026

Summary

  • Add S3-compliant 301 PermanentRedirect responses when clients request renamed accounts
  • Proxy detects renamed accounts via Source API (HTTP 301 + {"redirect_to": "new-account"}) and returns redirect with Location header and S3 XML error body
  • Product-level requests (/{old-account}/{product}/...) caught in fetch handler before gateway dispatch
  • Account-level list requests (/{old-account}?list-type=2) caught in AccountListHandler
  • Redirect responses are cached with same TTLs as normal API responses
  • 16 new unit tests for URL rewriting, S3 XML generation, and path segment extraction

Design

Key architectural decisions:

  • Registry-layer redirect: Source API signals renames, proxy short-circuits before backend resolution
  • #[serde(deny_unknown_fields)] on RedirectInfo prevents false positive redirect detection on cache hits
  • No redundant API calls: product-level and account-level redirects are checked in separate code paths

Test plan

  • 16 unit tests for redirect module (URL rewriting, XML generation, path parsing)
  • All 41 existing tests pass (pagination, routing, redirect)
  • cargo clippy clean on wasm32-unknown-unknown
  • Integration test with staging environment (requires Source API support for 301 responses)
  • Verify CORS headers on redirect responses
  • Verify S3 SDK clients follow 301 redirects correctly

Closes source-cooperative/source.coop#277

🤖 Generated with Claude Code

alukach and others added 7 commits March 27, 2026 23:17
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add pure-logic functions for building redirect paths, generating S3
PermanentRedirect XML responses, and extracting path segments for
account rename redirects. Includes 16 tests covering all functions.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Add ApiResponse enum and cached_fetch_with_redirect to handle HTTP 301
responses from the Source API, enabling the cache layer to distinguish
between normal data and redirect info for renamed accounts. Also add
Serialize derive to RedirectInfo for cache serialization.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Insert redirect short-circuit between path rewriting and gateway
dispatch in lib.rs. When the API reports an account rename, return a
301 with S3 PermanentRedirect XML body and Location header instead of
proxying. Also wire up redirect module imports and remove dead_code
annotations from registry redirect methods.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
- Add #[serde(deny_unknown_fields)] to RedirectInfo to prevent false
  positive redirect detection on cache hits
- Hoist registry creation above redirect check to avoid duplicate
  instantiation
- Only check product-level redirects in lib.rs; account-only requests
  are handled by AccountListHandler to avoid redundant API calls
- Replace .unwrap() with graceful error handling for Location header
  parsing in AccountListHandler
- Remove unnecessary #[allow(dead_code)] from redirect-aware cache
  functions

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link
Copy Markdown

🚀 Latest commit deployed to https://source-data-proxy-pr-124.source-coop.workers.dev

  • Date: 2026-03-30T05:51:22Z
  • Commit: feedbb6

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

[Feature] Clear procedure for user/org name change and redirect

1 participant