Thoth
A functional, expressive, asynchronous C++26 webdev library
Loading...
Searching...
No Matches
Url.hpp
Go to the documentation of this file.
1#pragma once
2#include <expected>
3#include <string>
5
6namespace Thoth::Http {
7 using string_view = std::string_view;
8 using string = std::string;
9
10 struct Url {
12 string scheme{};
15 string user{};
17 string host{};
19 int port{};
21 string path{};
25 string fragment{};
26
30 static std::expected<Url, RequestError> FromUrl(string_view rawUrl);
31
32
37 static string Encode(string_view str);
42 static std::expected<string, RequestError> TryDecode(string_view str);
43
45 [[nodiscard]] bool IsSecure() const;
46
47 bool operator==(const Url &) const;
48
49 private:
50 Url();
51
52 friend class std::formatter<Url>;
53 };
54}
55
56
57#include <Thoth/Http/Request/Url.tpp>
Definition Client.hpp:12
std::string string
Definition Url.hpp:8
std::string_view string_view
Definition Url.hpp:7
Definition QueryParams.hpp:11
Definition Url.hpp:10
static std::expected< string, RequestError > TryDecode(string_view str)
Tries to decode the text with Percent-Encoding.
string scheme
the given scheme. Can be "http" or "https" (it's "empty" after all).
Definition Url.hpp:12
string host
the hostname of the URL.
Definition Url.hpp:17
bool operator==(const Url &) const
static string Encode(string_view str)
Encodes a text with Percent-Encoding.
static std::expected< Url, RequestError > FromUrl(string_view rawUrl)
Tries to convert the given string into URL.
QueryParams query
the query of the URL.
Definition Url.hpp:23
string user
the userinfo of the URL, the optional part between the scheme and the host. eg: https://userinfo@@loc...
Definition Url.hpp:15
string path
the path of the URL.
Definition Url.hpp:21
string fragment
the fragment of the URL. Normally ignored in server side.
Definition Url.hpp:25
int port
the port of the URL. Goes from 0 to 65.535.
Definition Url.hpp:19
bool IsSecure() const
Check if the scheme is https.