summaryrefslogtreecommitdiff
path: root/AK/URL.h
blob: 2c17a53190f2377fe3a9bfc02f6f6ba2d695f038 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
#pragma once

#include <AK/AKString.h>
#include <AK/StringView.h>

namespace AK {

class URL {
public:
    URL() {}
    URL(const StringView&);
    URL(const char* string)
        : URL(StringView(string))
    {
    }
    URL(const String& string)
        : URL(string.view())
    {
    }

    bool is_valid() const { return m_valid; }
    String protocol() const { return m_protocol; }
    String host() const { return m_host; }
    String path() const { return m_path; }
    u16 port() const { return m_port; }

    String to_string() const;

private:
    bool parse(const StringView&);

    bool m_valid { false };
    u16 m_port { 80 };
    String m_protocol;
    String m_host;
    String m_path;
};

}

using AK::URL;

inline const LogStream& operator<<(const LogStream& stream, const URL& value)
{
    return stream << value.to_string();
}