2021-05-25 17:13:15 -03:00
|
|
|
/*
|
|
|
|
|
* Copyright (c) 2021, Max Wipfli <mail@maxwipfli.ch>
|
2024-03-18 00:22:27 -03:00
|
|
|
* Copyright (c) 2023-2024, Shannon Booth <shannon@serenityos.org>
|
2021-05-25 17:13:15 -03:00
|
|
|
*
|
|
|
|
|
* SPDX-License-Identifier: BSD-2-Clause
|
|
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
|
|
#include <AK/Optional.h>
|
|
|
|
|
#include <AK/StringView.h>
|
2026-01-16 11:14:26 -03:00
|
|
|
#include <LibTextCodec/Forward.h>
|
2024-03-18 00:22:27 -03:00
|
|
|
#include <LibURL/URL.h>
|
2021-05-25 17:13:15 -03:00
|
|
|
|
2024-03-18 00:22:27 -03:00
|
|
|
namespace URL {
|
2021-05-25 17:13:15 -03:00
|
|
|
|
2024-03-18 00:22:27 -03:00
|
|
|
class Parser {
|
2021-05-25 17:13:15 -03:00
|
|
|
public:
|
|
|
|
|
enum class State {
|
2026-04-05 12:00:12 -03:00
|
|
|
SchemeStart,
|
|
|
|
|
Scheme,
|
|
|
|
|
NoScheme,
|
|
|
|
|
SpecialRelativeOrAuthority,
|
|
|
|
|
PathOrAuthority,
|
|
|
|
|
Relative,
|
|
|
|
|
RelativeSlash,
|
|
|
|
|
SpecialAuthoritySlashes,
|
|
|
|
|
SpecialAuthorityIgnoreSlashes,
|
|
|
|
|
Authority,
|
|
|
|
|
Host,
|
|
|
|
|
Hostname,
|
|
|
|
|
Port,
|
|
|
|
|
File,
|
|
|
|
|
FileSlash,
|
|
|
|
|
FileHost,
|
|
|
|
|
PathStart,
|
|
|
|
|
Path,
|
|
|
|
|
OpaquePath,
|
|
|
|
|
Query,
|
|
|
|
|
Fragment,
|
2021-05-25 17:13:15 -03:00
|
|
|
};
|
|
|
|
|
|
2023-07-14 23:29:20 -03:00
|
|
|
// https://url.spec.whatwg.org/#concept-basic-url-parser
|
2025-01-09 12:50:34 -03:00
|
|
|
static Optional<URL> basic_parse(StringView input, Optional<URL const&> base_url = {}, URL* url = nullptr, Optional<State> state_override = {}, Optional<StringView> encoding = {});
|
2021-05-25 17:13:15 -03:00
|
|
|
|
2023-06-24 23:11:34 -03:00
|
|
|
// https://url.spec.whatwg.org/#string-percent-encode-after-encoding
|
2024-08-10 09:05:22 -03:00
|
|
|
static String percent_encode_after_encoding(TextCodec::Encoder&, StringView input, PercentEncodeSet percent_encode_set, bool space_as_plus = false);
|
2023-06-24 23:11:34 -03:00
|
|
|
|
2025-06-25 23:21:17 -03:00
|
|
|
static Optional<Host> parse_host(StringView input, bool is_opaque = false);
|
2021-05-25 17:13:15 -03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
}
|