Skip to content

Commit 333f6cb

Browse files
authored
fix(fetch): set correct type for Response.redirect() (#5212)
This Pull Request fixes/closes #5211. It changes the following: - Change `ResponseType::Basic` to `ResponseType::Default` in `Response.redirect()` - a new response type is `"default"` unless stated otherwise per the Fetch Standard. - Add a regression test asserting `Response.redirect().type === "default"`. Testing: ```bash cargo test -p boa_runtime response -- --nocapture ``` Spec reference: https://fetch.spec.whatwg.org/#dom-response-redirect
1 parent f90fd30 commit 333f6cb

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

core/runtime/src/fetch/response.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -319,7 +319,7 @@ impl JsResponse {
319319

320320
Ok(Self {
321321
url: js_string!(""),
322-
r#type: ResponseType::Basic,
322+
r#type: ResponseType::Default,
323323
status: status_code.as_u16(),
324324
status_text: JsString::from(status_code.canonical_reason().unwrap_or("")),
325325
headers: JsHeaders::from_http(headers),

core/runtime/src/fetch/tests/response.rs

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -193,6 +193,20 @@ fn response_redirect_default_status() {
193193
]);
194194
}
195195

196+
#[test]
197+
fn response_redirect_type_default() {
198+
run_test_actions([
199+
TestAction::harness(),
200+
TestAction::inspect_context(|ctx| register(&[], ctx)),
201+
TestAction::run(
202+
r#"
203+
assertEq(Response.redirect("http://unit.test").type, "default");
204+
assertEq(Response.redirect("http://unit.test", 301).type, "default");
205+
"#,
206+
),
207+
]);
208+
}
209+
196210
#[test]
197211
fn response_redirect_custom_status_and_coercion() {
198212
run_test_actions([

0 commit comments

Comments
 (0)