Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions core/runtime/src/fetch/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,11 +96,11 @@ impl TryIntoJs for ResponseType {
}
}

/// A null body status is a status that is 101, 103, 204, or 304.
/// A null body status is a status that is 101, 103, 204, 205, or 304.
///
/// See <https://fetch.spec.whatwg.org/#null-body-status>
fn is_null_body_status(status: u16) -> bool {
matches!(status, 101 | 103 | 204 | 304)
matches!(status, 101 | 103 | 204 | 205 | 304)
}

/// Validates that a string matches the `reason-phrase` token production.
Expand Down Expand Up @@ -239,7 +239,7 @@ fn initialize_response(
// Step 6.1: If response's status is a null body status, throw a TypeError.
if is_null_body_status(status) {
return Err(
js_error!(TypeError: "Response body is not allowed for null body status codes (101, 103, 204, 304)."),
js_error!(TypeError: "Response body is not allowed for null body status codes (101, 103, 204, 205, 304)."),
);
}

Expand Down
22 changes: 22 additions & 0 deletions core/runtime/src/fetch/tests/response.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,28 @@ fn response_error() {
]);
}

#[test]
fn response_constructor_null_body_status_throws() {
run_test_actions([
TestAction::harness(),
TestAction::inspect_context(|ctx| register(&[], ctx)),
TestAction::run(
r#"
for (const status of [204, 205, 304]) {
try {
new Response("x", { status });
throw Error("expected the call above to throw");
} catch (e) {
if (!(e instanceof TypeError)) {
throw e;
}
}
}
"#,
),
]);
}

#[test]
fn response_text() {
run_test_actions([
Expand Down
Loading