Skip to content

Response constructor has dummy implementation #4547

@max-lt

Description

@max-lt

Describe the bug
A clear and concise description of what the bug is.

Response constructor has dummy implementation

#[boa_class(rename = "Response")]
#[boa(rename_all = "camelCase")]
impl JsResponse {

    #[boa(constructor)]
    fn constructor(_body: Option<JsValue>, _options: JsResponseOptions) -> Self {
        Self::basic(js_string!(""), http::Response::new(Vec::new()))
    }

To Reproduce
Steps to reproduce the issue, or JavaScript code that causes this failure.

Both parameters are prefixed with _ and never used. This means:

  const response = new Response('Hello World', { status: 404 });
  console.log(await response.text()); // Returns "" (empty string)
  console.log(response.status);       // Returns 200 (default)

Expected behavior
Explain what you expected to happen, and what is happening instead.

The constructor should parse the body and options:

  const response = new Response('Hello World', { status: 404 });
  console.log(await response.text()); // Should return "Hello World"
  console.log(response.status);       // Should return 404

Build environment (please complete the following information):

  • OS: macOS (Darwin)
  • Version: 24.6.0
  • Target triple: aarch64-apple-darwin
  • Rustc version: rustc 1.90.0 (1159e78c4 2025-09-14)

Additional context

Workaround :

        // Override Response constructor with our working implementation
        // (until Boa fixes their constructor to actually use the body parameter)
        // TODO: Remove this when https://github.com/boa-dev/boa/issues/XXXXX is fixed
        let setup_response = r#"
            // Save native Response class
            const NativeResponse = globalThis.Response;
            const nativeFetch = globalThis.fetch;

            // Override Response constructor to make it actually work
            globalThis.Response = function(body, init) {
                init = init || {};
                this.body = String(body || '');
                this.status = init.status || 200;
                this.headers = init.headers || {};
                this.text = async function() {
                    return this.body;
                };
            };

            // Keep native fetch (uses NativeResponse internally)
            globalThis.fetch = nativeFetch;
        "#;

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions