16 #ifndef __GU_URI_HPP__
17 #define __GU_URI_HPP__
23 #include "gu_utils.hpp"
24 #include "gu_regex.hpp"
57 const std::string&
user()
const
68 const std::string&
host()
const
79 const std::string&
port()
const
85 Authority() : user_(), host_(), port_() { }
91 typedef std::vector<Authority> AuthorityList;
102 URI (
const std::string&,
bool strict =
true);
110 if (modified_) recompose();
122 return scheme_.str();
141 if (authority_.empty())
143 return authority_.front().user();
154 if (authority_.empty())
156 return authority_.front().host();
167 if (authority_.empty())
169 return authority_.front().port();
200 return fragment_.str();
208 void set_option(
const std::string& key,
const std::string& val)
212 void append_option(
const std::string& key,
const std::string& val)
225 const std::string&
get_option(
const std::string&)
const;
227 const std::string&
get_option(
const std::string& opt,
228 const std::string& def)
const
231 catch (NotFound& ) {
return def ; }
236 mutable std::string str_;
238 RegEx::Match scheme_;
239 AuthorityList authority_;
241 RegEx::Match fragment_;
247 void parse (
const std::string& s,
bool strict);
252 void recompose()
const;
257 static const char*
const uri_regex_;
258 static RegEx
const regex_;
261 inline std::ostream& operator<<(std::ostream& os,
const URI& uri)
263 os << uri.to_string();
std::multimap< std::string, std::string > URIQueryList
URIQueryList.
Definition: gu_uri.hpp:36
Utility class to parse URIs.
Definition: gu_uri.hpp:41
Definition: gu_regex.hpp:50
const AuthorityList & get_authority_list() const
Get authority list.
Definition: gu_uri.hpp:177
const std::string & get_path() const
Get URI path.
Definition: gu_uri.hpp:187
void set_query_param(const std::string &, const std::string &, bool override)
Add query param to URI.
const std::string & user() const
Get "user" part of authority.
Definition: gu_uri.hpp:57
const std::string & get_user() const
Get "user" part of the first entry in authority list.
Definition: gu_uri.hpp:139
const std::string & get_port() const
Get "port" part of the first entry in authority list.
Definition: gu_uri.hpp:165
const std::string & to_string() const
Get URI string.
Definition: gu_uri.hpp:108
const std::string & get_option(const std::string &) const
return opton by name,
const std::string & get_host() const
Get "host" part of the first entry in authority list.
Definition: gu_uri.hpp:152
URI(const std::string &, bool strict=true)
Construct URI from string.
const std::string & get_scheme() const
Get URI scheme.
Definition: gu_uri.hpp:120
const URIQueryList & get_query_list() const
Get URI query list.
Definition: gu_uri.hpp:219
std::string get_authority() const
Get URI authority component.
Definition: gu_uri.hpp:47
const std::string & host() const
Get "host" part of authority.
Definition: gu_uri.hpp:68
const std::string & get_fragment() const
Get URI path.
Definition: gu_uri.hpp:198
Definition: gu_exception.hpp:16
const std::string & port() const
Get "port" part of authority.
Definition: gu_uri.hpp:79