mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2025-07-28 11:49:44 +00:00
LibWeb/Fetch: Implement the "set the Sec-Fetch-Dest header" AO
This commit is contained in:
parent
6e3b2ce300
commit
f4af1833c1
Notes:
sideshowbarker
2024-07-17 17:06:59 +09:00
Author: https://github.com/jamierocks
Commit: f4af1833c1
Pull-request: https://github.com/SerenityOS/serenity/pull/24164
Reviewed-by: https://github.com/kennethmyhra ✅
2 changed files with 29 additions and 0 deletions
|
@ -2,6 +2,7 @@
|
|||
* Copyright (c) 2022-2023, Linus Groh <linusg@serenityos.org>
|
||||
* Copyright (c) 2023, Luke Wilde <lukew@serenityos.org>
|
||||
* Copyright (c) 2023, Sam Atkins <atkinssj@serenityos.org>
|
||||
* Copyright (c) 2024, Jamie Mansfield <jmansfield@cadixdev.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
@ -44,6 +45,7 @@
|
|||
#include <LibWeb/Platform/EventLoopPlugin.h>
|
||||
#include <LibWeb/ReferrerPolicy/AbstractOperations.h>
|
||||
#include <LibWeb/SRI/SRI.h>
|
||||
#include <LibWeb/SecureContexts/AbstractOperations.h>
|
||||
#include <LibWeb/WebIDL/DOMException.h>
|
||||
|
||||
namespace Web::Fetch::Fetching {
|
||||
|
@ -1992,4 +1994,29 @@ WebIDL::ExceptionOr<JS::NonnullGCPtr<PendingResponse>> cors_preflight_fetch(JS::
|
|||
return returned_pending_response;
|
||||
}
|
||||
|
||||
// https://w3c.github.io/webappsec-fetch-metadata/#abstract-opdef-set-dest
|
||||
void set_sec_fetch_dest_header(Infrastructure::Request& request)
|
||||
{
|
||||
// 1. Assert: r’s url is a potentially trustworthy URL.
|
||||
VERIFY(SecureContexts::is_url_potentially_trustworthy(request.url()) == SecureContexts::Trustworthiness::PotentiallyTrustworthy);
|
||||
|
||||
// 2. Let header be a Structured Header whose value is a token.
|
||||
// FIXME: This is handled below, as Serenity doesn't have APIs for RFC 8941.
|
||||
|
||||
// 3. If r’s destination is the empty string, set header’s value to the string "empty". Otherwise, set header’s value to r’s destination.
|
||||
ByteBuffer header_value;
|
||||
if (!request.destination().has_value()) {
|
||||
header_value = MUST(ByteBuffer::copy("empty"sv.bytes()));
|
||||
} else {
|
||||
header_value = MUST(ByteBuffer::copy(Infrastructure::request_destination_to_string(request.destination().value()).bytes()));
|
||||
}
|
||||
|
||||
// 4. Set a structured field value `Sec-Fetch-Dest`/header in r’s header list.
|
||||
auto header = Infrastructure::Header {
|
||||
.name = MUST(ByteBuffer::copy("Sec-Fetch-Dest"sv.bytes())),
|
||||
.value = move(header_value),
|
||||
};
|
||||
request.header_list()->append(move(header));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue