From 084cb4350ecd57954c16d560c93fad71ab8e5208 Mon Sep 17 00:00:00 2001 From: Aliaksandr Kalenik Date: Mon, 2 Oct 2023 19:29:15 +0200 Subject: [PATCH] LibWeb/Fetch: Include body and headers in Response for failed requests Fixes https://github.com/SerenityOS/serenity/issues/21290 --- Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp index 9a5dcb8647..7672b5aa72 100644 --- a/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp +++ b/Userland/Libraries/LibWeb/Fetch/Fetching/Fetching.cpp @@ -1776,7 +1776,7 @@ WebIDL::ExceptionOr> nonstandard_resource_load // FIXME: Set response status message pending_response->resolve(response); }, - [&realm, &vm, request, pending_response](auto& error, auto status_code, auto, auto&) { + [&realm, &vm, request, pending_response](auto& error, auto status_code, auto data, auto& response_headers) { dbgln_if(WEB_FETCH_DEBUG, "Fetch: ResourceLoader load for '{}' failed: {} (status {})", request->url(), error, status_code.value_or(0)); auto response = Infrastructure::Response::create(vm); // FIXME: This is ugly, ResourceLoader should tell us. @@ -1785,7 +1785,13 @@ WebIDL::ExceptionOr> nonstandard_resource_load } else { response->set_type(Infrastructure::Response::Type::Error); response->set_status(status_code.value_or(400)); - // FIXME: Set response status message and body + auto [body, _] = TRY_OR_IGNORE(extract_body(realm, data)); + response->set_body(move(body)); + for (auto const& [name, value] : response_headers) { + auto header = TRY_OR_IGNORE(Infrastructure::Header::from_string_pair(name, value)); + TRY_OR_IGNORE(response->header_list()->append(header)); + } + // FIXME: Set response status message } pending_response->resolve(response); });