2019-08-10 18:27:56 +03:00
|
|
|
#pragma once
|
|
|
|
|
2019-09-06 16:34:26 +03:00
|
|
|
#include <AK/String.h>
|
2019-08-10 18:27:56 +03:00
|
|
|
#include <AK/StringView.h>
|
|
|
|
|
|
|
|
namespace AK {
|
|
|
|
|
|
|
|
class URL {
|
|
|
|
public:
|
|
|
|
URL() {}
|
|
|
|
URL(const StringView&);
|
2019-08-10 20:31:37 +03:00
|
|
|
URL(const char* string)
|
|
|
|
: URL(StringView(string))
|
|
|
|
{
|
|
|
|
}
|
|
|
|
URL(const String& string)
|
|
|
|
: URL(string.view())
|
|
|
|
{
|
|
|
|
}
|
2019-08-10 18:27:56 +03:00
|
|
|
|
|
|
|
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();
|
|
|
|
}
|