Skip to content

feat(fetch): implement Response.ok/statusText and Body.text/bytes/arrayBuffer - #271

Open
Sonic-Y3k wants to merge 2 commits into
gost-dom:mainfrom
Sonic-Y3k:feat/response-and-body-surface
Open

feat(fetch): implement Response.ok/statusText and Body.text/bytes/arrayBuffer#271
Sonic-Y3k wants to merge 2 commits into
gost-dom:mainfrom
Sonic-Y3k:feat/response-and-body-surface

Conversation

@Sonic-Y3k

Copy link
Copy Markdown

Response.ok, Response.statusText, and the Body.text(), Body.bytes() and Body.arrayBuffer() consumers were unimplemented and threw "Not implemented". (Response.ok's error message invited an issue/PR.)

  • Response.Ok() (status in 200–299) and Response.StatusText() added to the Go fetch.Response type.
  • Body.text/bytes/arrayBuffer implemented as custom implementations.
  • Driven through the code generator (config in fetch_configuration.go); the regenerated files are committed and the codegen is idempotent.

Independent of #270 — both touch internal/fetch but in separate regions/files, so they merge in any order.

Testing: TestResponseOk/TestResponseStatusText plus a scripttests "Response surface" case (ok/status/statusText/text/json/bytes/arrayBuffer + 404).


AI disclosure: This change was developed with the help of an AI coding assistant. I've reviewed and tested it myself; it follows the existing conventions and the full test suite (main module, v8engine, sobekengine) passes locally.

@coderabbitai

coderabbitai Bot commented Jun 13, 2026

Copy link
Copy Markdown
Contributor

Review Change Stack

Warning

Review limit reached

@Sonic-Y3k, we couldn't start this review because you've reached your PR review rate limit.

More reviews will be available in 53 minutes and 31 seconds. Learn how PR review limits work.

Your organization has used up its prepaid credits, and credit purchases are no longer available. Enable the review add-on in the billing tab to keep reviews running — you're only billed for reviews past your plan's rate limits ($0.25/file).

⌛ How to resolve this issue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based credits.

🚦 How do rate limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please see our Fair Usage Limits Policy for further information.

ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: 064c3509-5b4e-437b-ae81-346089510873

📥 Commits

Reviewing files that changed from the base of the PR and between d14cd8a and 5a92f33.

📒 Files selected for processing (5)
  • internal/code-gen/scripting/configuration/fetch_configuration.go
  • internal/fetch/response_test.go
  • scripting/internal/fetch/body.go
  • scripting/internal/fetch/response.go
  • scripting/internal/scripttests/fetch_suite.go

Walkthrough

This PR extends the fetch API implementation by adding Response convenience methods and Body content readers. The core work introduces Response.Ok() (status range check) and Response.StatusText() (reason phrase extraction) to internal/fetch/fetch.go, along with unit tests. The code generator configuration is updated to treat these as custom implementations. The scripting layer then exposes these methods as JavaScript-callable bindings (Response_ok, Response_statusText, Body_text, Body_bytes, Body_arrayBuffer), and integration tests validate the complete behavior across success and error scenarios.

Possibly related PRs

  • gost-dom/browser#176: Refactors the Response struct in internal/fetch/fetch.go's status and underlying httpResponse handling as foundational work for the response plumbing that this PR builds upon.
🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Title check ✅ Passed The title accurately and specifically describes the main implementation: adding Response.ok/statusText and Body.text/bytes/arrayBuffer methods as previously unimplemented fetch API features.
Description check ✅ Passed The description is directly related to the changeset, providing context about what was unimplemented, listing the specific features added, explaining the implementation approach via code generation, and noting testing coverage.
Docstring Coverage ✅ Passed Docstring coverage is 85.00% which is sufficient. The required threshold is 80.00%.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.


Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Actionable comments posted: 3

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (1)
scripting/internal/fetch/body.go (1)

11-70: 🧹 Nitpick | 🔵 Trivial | 💤 Low value

Consider extracting common Body consumer pattern.

All four Body consumer methods (Body_json, Body_text, Body_bytes, Body_arrayBuffer) repeat the same pattern:

instance, err := js.As[fetch.Body](cbCtx.Instance())
if err != nil {
    return nil, err
}
return codec.EncodePromise(cbCtx, promise.ReadAll(instance), encoder)

A helper function could eliminate this duplication and improve maintainability:

func encodeBodyPromise[T any](
    cbCtx js.CallbackContext[T],
    encoder codec.Encoder[T, []byte],
) (js.Value[T], error) {
    instance, err := js.As[fetch.Body](cbCtx.Instance())
    if err != nil {
        return nil, err
    }
    return codec.EncodePromise(cbCtx, promise.ReadAll(instance), encoder)
}

Then each Body method becomes a one-liner: return encodeBodyPromise(cbCtx, encoderFunc).


ℹ️ Review info
⚙️ Run configuration

Configuration used: Organization UI

Review profile: ASSERTIVE

Plan: Pro

Run ID: dd1f5527-2b0a-43be-8c21-56830306707c

📥 Commits

Reviewing files that changed from the base of the PR and between ac2cda7 and 4f09dcb.

📒 Files selected for processing (8)
  • internal/code-gen/scripting/configuration/fetch_configuration.go
  • internal/fetch/fetch.go
  • internal/fetch/response_test.go
  • scripting/internal/fetch/body.go
  • scripting/internal/fetch/body_generated.go
  • scripting/internal/fetch/response.go
  • scripting/internal/fetch/response_generated.go
  • scripting/internal/scripttests/fetch_suite.go
💤 Files with no reviewable changes (2)
  • scripting/internal/fetch/response_generated.go
  • scripting/internal/fetch/body_generated.go

Comment thread scripting/internal/fetch/body.go
Comment thread scripting/internal/scripttests/fetch_suite.go Outdated
Comment thread scripting/internal/scripttests/fetch_suite.go
…ayBuffer

Response.ok (status in 200-299), Response.statusText, and the Body.text(),
Body.bytes() and Body.arrayBuffer() consumers were previously unimplemented and
threw "Not implemented". Implemented via the code generator (custom
implementations) with unit tests and a scripttests "Response surface" case.
@Sonic-Y3k
Sonic-Y3k force-pushed the feat/response-and-body-surface branch from 4f09dcb to acb4c6c Compare June 13, 2026 14:16
@Sonic-Y3k

Copy link
Copy Markdown
Author

Follow-up in d14cd8a:

  • Body consumer duplication (outside-diff nitpick): extracted the shared js.As + EncodePromise pattern into an encodeBodyPromise helper. Body_json/text/bytes/arrayBuffer are now one-liners that just pass their encoder.
  • Docstring coverage: added doc comments to the Response/Body script bindings, their unit/script tests, and the code-gen configureFetchSpecs config, which were the functions dragging the ratio below the 80% threshold.

No generated files changed (codegen is still idempotent), and the suite passes on both the v8engine and sobekengine engines.

…helper

Add doc comments to the Response/Body script bindings, their tests, and the
code-gen Fetch configuration so the docstring-coverage check passes, and
extract a shared encodeBodyPromise helper to remove the duplicated
js.As/EncodePromise pattern across the json/text/bytes/arrayBuffer consumers.
@Sonic-Y3k
Sonic-Y3k force-pushed the feat/response-and-body-surface branch from d14cd8a to 5a92f33 Compare June 27, 2026 11:31
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant