ladybird/Userland/Libraries/LibWeb/Fetch/Infrastructure/URL.cpp
Shannon Booth e800605ad3 AK+LibURL: Move AK::URL into a new URL library
This URL library ends up being a relatively fundamental base library of
the system, as LibCore depends on LibURL.

This change has two main benefits:
 * Moving AK back more towards being an agnostic library that can
   be used between the kernel and userspace. URL has never really fit
   that description - and is not used in the kernel.
 * URL _should_ depend on LibUnicode, as it needs punnycode support.
   However, it's not really possible to do this inside of AK as it can't
   depend on any external library. This change brings us a little closer
   to being able to do that, but unfortunately we aren't there quite
   yet, as the code generators depend on LibCore.
2024-03-18 14:06:28 -04:00

33 lines
988 B
C++

/*
* Copyright (c) 2022, Linus Groh <linusg@serenityos.org>
* Copyright (c) 2022, Andreas Kling <kling@serenityos.org>
*
* SPDX-License-Identifier: BSD-2-Clause
*/
#include <LibWeb/Fetch/Infrastructure/URL.h>
namespace Web::Fetch::Infrastructure {
// https://fetch.spec.whatwg.org/#is-local
bool is_local_url(URL::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; });
}
// 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; });
}
}