Repository navigation
feat: public key-addressed web seam fetchWebKey(key, request) - #203
Merged
Merged
Conversation
Promotes the internal key-addressed path to the public web API. The caller names the S3 key; the Request contributes only method (GET/HEAD) and conditional/Range headers — the request URL plays no role in key selection. fetchWeb() now derives the key from the URL and delegates to fetchWebKey(), so both share one HTTP <-> S3 translation path. Lets consumers with a non-identity URL->key mapping (a prefix, a /files/* mount) avoid round-tripping the key through URL encode/decode — which otherwise corrupts keys containing %, +, spaces, or other reserved characters unless the consumer's encoder and s3proxy's decoder agree exactly. The key is used verbatim. No behavior change to fetchWeb (same key derivation, same Response). Adds a fetchWebKey test suite incl. the reserved-character case that fetchWeb can't carry via the URL, plus README narrative + API-reference docs. Closes #162. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Factor the shared { url, method, headers } lift into a private
webToHttpRequest() helper so the method/header conversion lives in one place
(clears Codacy's duplicate-block findings introduced by fetchWebKey).
Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
simplify:
- fetchWeb derives the key with headers:{} instead of spreading
webToHttpRequest — parseRequest reads only the path, so the second
header materialization per request is removed.
- trim the editorial paragraph duplicated from the README out of the
fetchWebKey JSDoc.
code-review:
- docs claimed the Request's "conditional/Range" headers are honored, but
fetchKey forwards only Range (no If-None-Match/If-Modified-Since anywhere
on the fetch path). Correct the JSDoc + README to "Range" only.
- rewrite the README example to a non-URL key source: the previous one
derived the key from Hono's c.req.path, which is already percent-decoded,
so it was NOT verbatim and defeated the feature's own point.
- fetchWebKey now rejects a null-byte key with the typed InvalidRequest,
matching the guard parseRequest applies on every other entry point
(was: verbatim key -> generic 500). Adds a test.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Both the fetchWeb and fetchWebKey suites used an identical beforeEach/afterEach + `let proxy` block; adding the second suite duplicated it (Codacy flagged the clone). Lift the setup to file scope so it is defined once and applies to both describes. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This was referenced Nov 1, 2026
Merged
gmoon
added a commit
that referenced
this pull request
Nov 1, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #162.
Promotes the internal key-addressed path to the public web API.
The caller names the S3 key; the
Requestcontributes only method (GET/HEAD) and conditional/Rangeheaders — the URL plays no role in key selection.fetchWeb()now derives the key from the URL and delegates tofetchWebKey(), so both share one HTTP↔S3 translation path (Range→206, missing/denied→typed 404/403, header mapping, HEAD, Node→Web stream).Why
Consumers whose URL→key mapping isn't identity (a prefix, a
/files/*mount) currently fabricate a syntheticRequestto smuggle the key through the URL, round-tripping it key → URL-encode → Request → URL-parse → key. That's wasteful, splits ownership of path→key logic, and — the real hazard — corrupts keys containing%,+, spaces, or other reserved characters unless the consumer's encoder and s3proxy's decoder agree exactly.fetchWebKeyuses the key verbatim.Per the scope note on the issue: this is not SDK-duplication — the value is the HTTP translation. A true SDK duplicate (
fetchKey(key)→stream, no HTTP) stays private.Changes
src/index.ts: add publicfetchWebKey; refactorfetchWebto delegate. No behavior change tofetchWeb(identical key derivation +Response).fetchWebKeysuite — verbatim key, delegation equivalence, Range→206, HEAD, typed 404, and a reserved-character (%) case thatfetchWebcan't carry via the URL (asserts it throwsInvalidRequest)./files/*example + the "use the SDK if you don't need a Response" decision rule) and API reference.Verification
npm run type-check/build/lintcleannpm run test:unit→ 83/83 (was 76; +7)🤖 Generated with Claude Code