diff --git a/Userland/Libraries/LibWeb/CMakeLists.txt b/Userland/Libraries/LibWeb/CMakeLists.txt index 8665b6e697..3e19af5065 100644 --- a/Userland/Libraries/LibWeb/CMakeLists.txt +++ b/Userland/Libraries/LibWeb/CMakeLists.txt @@ -118,6 +118,7 @@ set(SOURCES Encoding/TextDecoder.cpp Encoding/TextEncoder.cpp Fetch/AbstractOperations.cpp + Fetch/Infrastructure/URL.cpp FontCache.cpp Geometry/DOMRectList.cpp HTML/AttributeNames.cpp diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.cpp new file mode 100644 index 0000000000..34ab04bef9 --- /dev/null +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.cpp @@ -0,0 +1,18 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#include + +namespace Web::Fetch { + +// https://fetch.spec.whatwg.org/#is-local +bool is_local_url(AK::URL const& url) +{ + // A URL is local if its scheme is a local scheme. + return any_of(LOCAL_SCHEMES, [&](auto scheme) { return url.scheme() == scheme; }); +} + +} diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.h new file mode 100644 index 0000000000..d235577398 --- /dev/null +++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.h @@ -0,0 +1,34 @@ +/* + * Copyright (c) 2022, Linus Groh + * + * SPDX-License-Identifier: BSD-2-Clause + */ + +#pragma once + +#include +#include + +namespace Web::Fetch { + +// https://fetch.spec.whatwg.org/#local-scheme +// A local scheme is "about", "blob", or "data". +inline constexpr Array LOCAL_SCHEMES = { + "about"sv, "blob"sv, "data"sv +}; + +// https://fetch.spec.whatwg.org/#http-scheme +// An HTTP(S) scheme is "http" or "https". +inline constexpr Array HTTP_SCHEMES = { + "http"sv, "https"sv +}; + +// https://fetch.spec.whatwg.org/#fetch-scheme +// A fetch scheme is "about", "blob", "data", "file", or an HTTP(S) scheme. +inline constexpr Array FETCH_SCHEMES = { + "about"sv, "blob"sv, "data"sv, "file"sv, "http"sv, "https"sv +}; + +[[nodiscard]] bool is_local_url(AK::URL const&); + +}