mirror of
https://github.com/LadybirdBrowser/ladybird.git
synced 2024-09-30 08:41:15 +00:00
LibWeb: Implement 'Should response be blocked due to its MIME type?' AO
This commit is contained in:
parent
62228f0870
commit
7e46150a71
Notes:
sideshowbarker
2024-07-17 09:41:18 +09:00
Author: https://github.com/linusg Commit: https://github.com/SerenityOS/serenity/commit/7e46150a71 Pull-request: https://github.com/SerenityOS/serenity/pull/15795 Reviewed-by: https://github.com/ADKaster Reviewed-by: https://github.com/awesomekling Reviewed-by: https://github.com/davidot ✅
|
@ -131,6 +131,7 @@ set(SOURCES
|
|||
Fetch/Infrastructure/HTTP/Requests.cpp
|
||||
Fetch/Infrastructure/HTTP/Responses.cpp
|
||||
Fetch/Infrastructure/HTTP/Statuses.cpp
|
||||
Fetch/Infrastructure/MimeTypeBlocking.cpp
|
||||
Fetch/Infrastructure/PortBlocking.cpp
|
||||
Fetch/Infrastructure/URL.cpp
|
||||
Fetch/Request.cpp
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Requests.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/HTTP/Responses.h>
|
||||
#include <LibWeb/Fetch/Infrastructure/MimeTypeBlocking.h>
|
||||
|
||||
namespace Web::Fetch::Infrastructure {
|
||||
|
||||
// https://fetch.spec.whatwg.org/#ref-for-should-response-to-request-be-blocked-due-to-mime-type?
|
||||
RequestOrResponseBlocking should_response_to_request_be_blocked_due_to_its_mime_type(Response const& response, Request const& request)
|
||||
{
|
||||
// 1. Let mimeType be the result of extracting a MIME type from response’s header list.
|
||||
auto mime_type = response.header_list()->extract_mime_type();
|
||||
|
||||
// 2. If mimeType is failure, then return allowed.
|
||||
if (!mime_type.has_value())
|
||||
return RequestOrResponseBlocking::Allowed;
|
||||
|
||||
// 3. Let destination be request’s destination.
|
||||
// 4. If destination is script-like and one of the following is true, then return blocked:
|
||||
if (request.destination_is_script_like() && (
|
||||
// - mimeType’s essence starts with "audio/", "image/", or "video/".
|
||||
any_of(Array { "audio/"sv, "image/"sv, "video/"sv }, [&](auto prefix) { return mime_type->essence().starts_with(prefix); })
|
||||
// - mimeType’s essence is "text/csv".
|
||||
|| mime_type->essence() == "text/csv"sv)) {
|
||||
return RequestOrResponseBlocking::Blocked;
|
||||
}
|
||||
|
||||
// 5. Return allowed.
|
||||
return RequestOrResponseBlocking::Allowed;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,16 @@
|
|||
/*
|
||||
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
|
||||
*
|
||||
* SPDX-License-Identifier: BSD-2-Clause
|
||||
*/
|
||||
|
||||
#pragma once
|
||||
|
||||
#include <LibWeb/Fetch/Infrastructure/RequestOrResponseBlocking.h>
|
||||
#include <LibWeb/Forward.h>
|
||||
|
||||
namespace Web::Fetch::Infrastructure {
|
||||
|
||||
[[nodiscard]] RequestOrResponseBlocking should_response_to_request_be_blocked_due_to_its_mime_type(Response const&, Request const&);
|
||||
|
||||
}
|
Loading…
Reference in a new issue