Skip to content

feat(runtime): add Request.clone() and Response.clone() per Fetch Standard §7.3/§7.4#4993

Merged
jedel1043 merged 2 commits intoboa-dev:mainfrom
Nakshatra480:feature/request-response-clone-4992
Mar 18, 2026
Merged

feat(runtime): add Request.clone() and Response.clone() per Fetch Standard §7.3/§7.4#4993
jedel1043 merged 2 commits intoboa-dev:mainfrom
Nakshatra480:feature/request-response-clone-4992

Conversation

@Nakshatra480
Copy link
Copy Markdown
Contributor

@Nakshatra480 Nakshatra480 commented Mar 11, 2026

Summary

Closes #4992

Implements clone() on Request and Response objects in boa_runtime per Fetch Standard §7.3 and §7.4.

Changes

  • headers.rs: Added pub(crate) fn deep_clone() on JsHeaders to produce a fully independent header map copy.
  • request.rs: Added body_used: Cell<bool> tracking field and clone() method. Throws TypeError if body is already used.
  • response.rs: Added body_used: Cell<bool> tracking field and clone() method. Throws TypeError if body is already used. bytes(), text(), and json() now also throw TypeError on a consumed body and mark it as used.

Behavior

  • request.clone() returns a new Request with an independent copy of method, headers, and body. Shares AbortSignal when signal support is wired into JsRequest (follow-up).
  • response.clone() returns a new Response with independent copies of status, headers, body, and url.
  • Both throw TypeError if the body has already been consumed.

Testing

  • cargo check -p boa_runtime passes
  • cargo clippy --all-features --all-targets -- -D warnings passes
  • cargo fmt --all -- --check passes
  • cargo test -p boa_runtime passes

Spec References

@Nakshatra480 Nakshatra480 requested a review from a team as a code owner March 11, 2026 01:45
@github-actions
Copy link
Copy Markdown

github-actions bot commented Mar 11, 2026

Test262 conformance changes

Test result main count PR count difference
Total 52,963 52,963 0
Passed 50,073 50,073 0
Ignored 2,072 2,072 0
Failed 818 818 0
Panics 0 0 0
Conformance 94.54% 94.54% 0.00%

Tested main commit: daf86d30277a5c1fb353825347f75c1d83516905
Tested PR commit: 0a0960383ec9d20a8db1b0c8ea01d89250733fbf
Compare commits: daf86d3...0a09603

@codecov
Copy link
Copy Markdown

codecov bot commented Mar 11, 2026

Codecov Report

✅ All modified and coverable lines are covered by tests.
✅ Project coverage is 59.36%. Comparing base (6ddc2b4) to head (0a09603).
⚠️ Report is 885 commits behind head on main.

Additional details and impacted files
@@             Coverage Diff             @@
##             main    #4993       +/-   ##
===========================================
+ Coverage   47.24%   59.36%   +12.11%     
===========================================
  Files         476      580      +104     
  Lines       46892    63160    +16268     
===========================================
+ Hits        22154    37493    +15339     
- Misses      24738    25667      +929     

☔ View full report in Codecov by Sentry.
📢 Have feedback on the report? Share it here.

🚀 New features to boost your workflow:
  • ❄️ Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • 📦 JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

@Nakshatra480
Copy link
Copy Markdown
Contributor Author

Hi @jedel1043 can you pls review this pr whenever you get a chance.

@jedel1043 jedel1043 added A-Enhancement New feature or request Waiting On Author Waiting on PR changes from the author C-Runtime Issues and PRs related to Boa's runtime features labels Mar 16, 2026
@jedel1043 jedel1043 added this to the v1.0.0 milestone Mar 16, 2026
@Nakshatra480 Nakshatra480 marked this pull request as draft March 17, 2026 07:09
@Nakshatra480 Nakshatra480 force-pushed the feature/request-response-clone-4992 branch from a024ef8 to 1989e57 Compare March 17, 2026 10:26
@github-actions github-actions bot added Waiting On Review Waiting on reviews from the maintainers C-Builtins PRs and Issues related to builtins/intrinsics labels Mar 17, 2026
@Nakshatra480 Nakshatra480 force-pushed the feature/request-response-clone-4992 branch from 1989e57 to 5c14131 Compare March 17, 2026 11:56
@github-actions github-actions bot added the C-Tests Issues and PRs related to the tests. label Mar 17, 2026
…ndard §7.3/§7.4

- Request.clone() deep-copies method/headers/body; shares signal per spec
- Response.clone() deep-copies all fields including independent headers
- headers.rs: add deep_clone() for spec-compliant header independence

Closes boa-dev#4992
@Nakshatra480 Nakshatra480 force-pushed the feature/request-response-clone-4992 branch from 5c14131 to ae8bb92 Compare March 17, 2026 12:08
@Nakshatra480 Nakshatra480 marked this pull request as ready for review March 17, 2026 12:27
@Nakshatra480 Nakshatra480 requested a review from jedel1043 March 17, 2026 12:27
@jedel1043 jedel1043 removed the Waiting On Author Waiting on PR changes from the author label Mar 18, 2026
Copy link
Copy Markdown
Member

@jedel1043 jedel1043 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

Ping me when you resolve the conflicts so that we can merge

…ponse-clone-4992

# Conflicts:
#	core/runtime/src/fetch/tests/response.rs
@Nakshatra480 Nakshatra480 requested a review from jedel1043 March 18, 2026 16:06
@Nakshatra480
Copy link
Copy Markdown
Contributor Author

@jedel1043 i have resolved the merge conflicts.

@jedel1043 jedel1043 added this pull request to the merge queue Mar 18, 2026
Merged via the queue into boa-dev:main with commit 509adef Mar 18, 2026
22 checks passed
@github-actions github-actions bot removed the Waiting On Review Waiting on reviews from the maintainers label Mar 18, 2026
@Nakshatra480 Nakshatra480 deleted the feature/request-response-clone-4992 branch March 18, 2026 18:26
@Nakshatra480
Copy link
Copy Markdown
Contributor Author

Thanks Jedel

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

Labels

A-Enhancement New feature or request C-Builtins PRs and Issues related to builtins/intrinsics C-Runtime Issues and PRs related to Boa's runtime features C-Tests Issues and PRs related to the tests.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Request.clone() and Response.clone() to boa_runtime fetch

2 participants