From bd62fe9c337bd2915b7385252b2de5bc86b0452b Mon Sep 17 00:00:00 2001 From: Luke Wilde Date: Sun, 18 Jun 2023 16:27:05 +0100 Subject: [PATCH] LibWeb: Set method, headers and Content-Length in BC navigation This is all ad-hoc, but will disappear when we switch to navigables. --- .../Libraries/LibWeb/HTML/BrowsingContext.cpp | 16 +++++++++++++++- 1 file changed, 15 insertions(+), 1 deletion(-) diff --git a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp index c0118956d9..b1e1b6d8dc 100644 --- a/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp +++ b/Userland/Libraries/LibWeb/HTML/BrowsingContext.cpp @@ -1220,7 +1220,21 @@ WebIDL::ExceptionOr BrowsingContext::navigate( (void)process_response_end_of_body; // AD-HOC: - loader().load(resource->url(), FrameLoader::Type::IFrame); + auto request = LoadRequest::create_for_url_on_page(resource->url(), page()); + request.set_method(DeprecatedString { resource->method() }); + for (auto& header : *resource->header_list()) { + request.set_header(DeprecatedString { header.name.bytes() }, DeprecatedString { header.value.bytes() }); + } + if (request.method() == "POST"sv) { + if (resource->body().has()) { + auto const& byte_buffer = resource->body().get(); + request.set_body(byte_buffer); + request.set_header("Content-Length", DeprecatedString::number(byte_buffer.size())); + } else { + request.set_header("Content-Length", DeprecatedString::number(0)); + } + } + loader().load(request, FrameLoader::Type::Navigation); return {}; }