summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndreas Kling <kling@serenityos.org>2022-09-21 10:38:06 +0200
committerAndreas Kling <kling@serenityos.org>2022-09-21 11:51:18 +0200
commit66f4e2b3b025fde4ca94872c59c5b3b2c354fed9 (patch)
tree673453095011e4a396549e3d6d998a74438eba7e
parentb02402e116da46d8ec51d3e418f83d12b8377fbe (diff)
downloadserenity-66f4e2b3b025fde4ca94872c59c5b3b2c354fed9.zip
LibWeb: Add two more scheme helpers to the Fetch infrastructure
-rw-r--r--Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.cpp15
-rw-r--r--Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.h3
2 files changed, 18 insertions, 0 deletions
diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.cpp b/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.cpp
index 9ed3612763..2c1f0bfeea 100644
--- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.cpp
+++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.cpp
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -15,4 +16,18 @@ bool is_local_url(AK::URL const& url)
return any_of(LOCAL_SCHEMES, [&](auto scheme) { return url.scheme() == scheme; });
}
+// https://fetch.spec.whatwg.org/#fetch-scheme
+bool is_fetch_scheme(StringView scheme)
+{
+ // A fetch scheme is "about", "blob", "data", "file", or an HTTP(S) scheme.
+ return any_of(FETCH_SCHEMES, [&](auto fetch_scheme) { return scheme == fetch_scheme; });
+}
+
+// https://fetch.spec.whatwg.org/#http-scheme
+bool is_http_or_https_scheme(StringView scheme)
+{
+ // An HTTP(S) scheme is "http" or "https".
+ return any_of(HTTP_SCHEMES, [&](auto http_scheme) { return scheme == http_scheme; });
+}
+
}
diff --git a/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.h b/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.h
index 17d2497148..908ca11457 100644
--- a/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.h
+++ b/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.h
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
+ * Copyright (c) 2022, Andreas Kling <linusg@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
@@ -30,5 +31,7 @@ inline constexpr Array FETCH_SCHEMES = {
};
[[nodiscard]] bool is_local_url(AK::URL const&);
+[[nodiscard]] bool is_fetch_scheme(StringView);
+[[nodiscard]] bool is_http_or_https_scheme(StringView);
}