[R2] Fix custom header middleware examples - #32596
Open
rdimaio wants to merge 1 commit into
Open
Conversation
rdimaio
requested review from
a team,
aninibread,
elithrar,
harshil1712,
helloimalastair and
jonesphillip
as code owners
August 7, 2026 09:42
Contributor
Review🚨 2 critical, 👉 Fix in your agent 👈Fix the following review findings in PR #32596 (https://github.com/cloudflare/cloudflare-docs/pull/32596).
Before making changes, review each finding and present a brief summary table:
- For each finding, state whether you agree, disagree, or need clarification
- If you disagree (e.g. the fix requires disproportionate effort for minimal benefit,
or the finding is factually incorrect), explain why
- If you need clarification before deciding, ask those questions
- Then share your plan for which issues to tackle and in what order
After triaging, follow this order:
1. Post a comment on this PR for any findings you are skipping, with the finding ID and your reasoning.
2. Then commit the fixes for the legitimate findings.
The comment must come before the commit — the bot reads PR comments when a new
push triggers a review, so skip comments posted after the push will be missed.
---
## Code Review
### Critical (2)
#### CR-ecff8637db23 · Incorrect module import
- **File:** `src/content/docs/r2/examples/aws/custom-header.mdx` line 49
- **Issue:** The example imports `HttpRequest` from `@smithy/core/protocols`, but the runtime `HttpRequest` class (and its `isInstance` method) is exported from `@smithy/protocol-http`. This subpath does not exist in `@smithy/core`, so users copying the snippet will get a module-resolution or build error.
- **Fix:** Change this import to `import { HttpRequest } from "@smithy/protocol-http";`. The same correction is needed at line 132.
#### CR-72622b8fb770 · Incorrect module import
- **File:** `src/content/docs/r2/examples/aws/custom-header.mdx` line 132
- **Issue:** This TypeScript snippet repeats the same incorrect import at line 49: `HttpRequest` is not exported from `@smithy/core/protocols`.
- **Fix:** Change this import to `import { HttpRequest } from "@smithy/protocol-http";`.
---
## Style Guide Review
### Warnings (1)
#### SG-45b5e0f0ae5d · Internal links should use root-relative paths
- **File:** `src/content/docs/r2/examples/aws/custom-header.mdx` line 138
- **Issue:** Comment includes the full internal URL `https://developers.cloudflare.com/r2/api/tokens`.
- **Fix:** Use a root-relative path with a trailing slash: `/r2/api/tokens/`.
Code ReviewThis code review is in beta and may not always be helpful — use your judgment. Critical (2)
ConventionsNo convention issues found. Style Guide ReviewWarnings (1)
CommandsOnly codeowners can run commands. Post a comment with the command to trigger it.
|
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.
Summary
Fixes the R2 AWS SDK for JavaScript v3 examples by narrowing middleware requests to Smithy
HttpRequestobjects and updating their header maps directly.Current Smithy middleware types define
args.requestasunknownand require callers to guard it as an HTTP request before modification. The originalRequestInitcast produced strict TypeScript errors becauseRequestInit.headersmay be undefined and itsHeadersInittype cannot be indexed by header name.The corrected examples compile under strict TypeScript with the current AWS SDK. Runtime testing with a stub request handler also confirmed that both custom headers reach the serialized S3 request.
Documentation checklist