5#include <boost/fusion/include/adapt_struct.hpp>
6#include <boost/spirit/home/x3/support/ast/position_tagged.hpp>
7#include <boost/leaf.hpp>
11#include <unordered_map>
17 struct Url : boost::spirit::x3::position_tagged
19 struct UserInfo : boost::spirit::x3::position_tagged
26 : boost::spirit::x3::position_tagged
27 , std::variant<std::string, Ipv4, Ipv6>
29 using base_type = std::variant<std::string, Ipv4, Ipv6>;
30 using base_type::variant;
42 struct Authority : boost::spirit::x3::position_tagged
44 struct Remote : boost::spirit::x3::position_tagged
47 std::optional<unsigned short>
port{};
49 std::optional<Url::UserInfo>
userInfo{std::nullopt};
55 std::vector<std::string>
path;
56 std::unordered_map<std::string, std::string>
query;
66 std::string
toString(
bool doUrlEncode =
true,
bool includeFragment =
true)
const;
106 static boost::leaf::result<Url>
fromString(std::string url);
115 static boost::leaf::result<std::vector<std::string>>
parsePath(std::string
const&
path);
123BOOST_FUSION_ADAPT_STRUCT(
Roar::Url, scheme, authority, path, query, fragment)
static constexpr int port
Definition main.cpp:16
Definition authorization.hpp:10
Url::Host host
Definition url.hpp:46
std::optional< unsigned short > port
Definition url.hpp:47
Remote remote
Definition url.hpp:50
std::optional< Url::UserInfo > userInfo
Definition url.hpp:49
base_type & as_variant()
Definition url.hpp:36
base_type const & as_variant() const
Definition url.hpp:32
std::variant< std::string, Ipv4, Ipv6 > base_type
Definition url.hpp:29
std::optional< std::string > password
Definition url.hpp:22
std::string user
Definition url.hpp:21
std::string scheme
Definition url.hpp:53
std::string fragment
Definition url.hpp:57
static boost::leaf::result< std::vector< std::string > > parsePath(std::string const &path)
Splits up a path string into a vector compatible with this class. An empty path returns an empty vect...
Definition url.cpp:303
std::vector< std::string > path
Definition url.hpp:55
std::string schemeAndAuthority(bool doUrlEncode=true) const
Converts the authority part and scheme to string: "https://user:password@domain.com:770".
Definition url.cpp:216
std::string hostAsString() const
Returns the host part of the url as a string. Does not include the port! IPv6 addresses will be enclo...
Definition url.cpp:223
std::string pathAsString(bool doUrlEncode=true) const
Will only create the path as a string with a leading slash: "/path/to/resource".
Definition url.cpp:180
std::string toString(bool doUrlEncode=true, bool includeFragment=true) const
Converts the url to a string containing all parts: https://u:p@bla.com:80/path?k=v.
Definition url.cpp:193
Authority authority
Definition url.hpp:54
std::string getAuthority(bool doUrlEncode) const
Converts the entire authority part to string: "user:password@domain.com:770".
Definition url.cpp:240
std::unordered_map< std::string, std::string > query
Definition url.hpp:56
static boost::leaf::result< Url > fromString(std::string url)
Parses a string that is a url.
Definition url.cpp:270