Skip to content

[R2] Fix custom header middleware examples - #32596

Open
rdimaio wants to merge 1 commit into
cloudflare:productionfrom
rdimaio:r2-fix-sdk-v3-custom-header
Open

[R2] Fix custom header middleware examples#32596
rdimaio wants to merge 1 commit into
cloudflare:productionfrom
rdimaio:r2-fix-sdk-v3-custom-header

Conversation

@rdimaio

@rdimaio rdimaio commented Aug 7, 2026

Copy link
Copy Markdown
Collaborator

Summary

Fixes the R2 AWS SDK for JavaScript v3 examples by narrowing middleware requests to Smithy HttpRequest objects and updating their header maps directly.

Current Smithy middleware types define args.request as unknown and require callers to guard it as an HTTP request before modification. The original RequestInit cast produced strict TypeScript errors because RequestInit.headers may be undefined and its HeadersInit type 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

@cloudflare-docs-bot

cloudflare-docs-bot Bot commented Aug 7, 2026

Copy link
Copy Markdown
Contributor

Review

🚨 2 critical, ⚠️ 1 warning found in commit 92abc82.

👉 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 Review

This code review is in beta and may not always be helpful — use your judgment.

Critical (2)
File Issue
r2/examples/aws/custom-header.mdx line 49 Incorrect module import — 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.
r2/examples/aws/custom-header.mdx line 132 Incorrect module import — 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";.

Conventions

No convention issues found.

Style Guide Review

Warnings (1)
File Issue
r2/examples/aws/custom-header.mdx line 138 Internal links should use root-relative paths — 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/.
Commands

Only codeowners can run commands. Post a comment with the command to trigger it.

Command Description
/review Runs a review now. Incremental if a prior review exists, full if not.
/full-review Re-reviews the entire PR diff from scratch, ignoring incremental history. Useful after a rebase, when you want a fresh review, or if the bot gets out of sync and reports issues that no longer exist.
/ignore-review-limit Permanently lifts the 2-review automatic limit for this PR. Future pushes will trigger reviews as normal.
/disable-auto-review Stops automatic reviews from triggering on future pushes to this PR. Codeowners can still run /review or /full-review manually.
/rebase Rebases the PR branch against production. On conflict, attempts to resolve automatically using AI. Stops with an explanation if confidence is not high enough.

@github-actions github-actions Bot added size/xs product:r2 R2 object storage: https://developers.cloudflare.com/r2 and removed size/xs labels Aug 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

product:r2 R2 object storage: https://developers.cloudflare.com/r2

Projects

None yet

Development

Successfully merging this pull request may close these issues.

6 participants