28 #ifndef WEBSOCKETPP_URI_HPP
29 #define WEBSOCKETPP_URI_HPP
31 #include <websocketpp/common/memory.hpp>
32 #include <websocketpp/error.hpp>
50 explicit uri(std::string
const & uri_string) : m_valid(
false) {
51 std::string::const_iterator it;
52 std::string::const_iterator temp;
56 it = uri_string.begin();
58 if (std::equal(it,it+6,
"wss://")) {
62 }
else if (std::equal(it,it+5,
"ws://")) {
66 }
else if (std::equal(it,it+7,
"http://")) {
70 }
else if (std::equal(it,it+8,
"https://")) {
91 while (temp != uri_string.end()) {
98 if (temp == uri_string.end()) {
103 m_host.append(it,temp);
106 if (it == uri_string.end()) {
108 }
else if (*it ==
'/') {
111 }
else if (*it ==
':') {
122 if (it == uri_string.end()) {
125 }
else if (*it ==
'/') {
127 }
else if (*it ==
':') {
138 std::string port =
"";
140 if (it == uri_string.end()) {
146 }
else if (*it ==
'/') {
155 m_port = get_port_from_string(port, ec);
162 m_resource.append(it,uri_string.end());
168 uri(
bool secure, std::string
const & host, uint16_t port,
169 std::string
const & resource)
170 : m_scheme(secure ?
"wss" :
"ws")
172 , m_resource(resource ==
"" ?
"/" : resource)
177 uri(
bool secure, std::string
const & host, std::string
const & resource)
178 : m_scheme(secure ?
"wss" :
"ws")
180 , m_resource(resource ==
"" ?
"/" : resource)
181 , m_port(secure ? uri_default_secure_port : uri_default_port)
185 uri(
bool secure, std::string
const & host, std::string
const & port,
186 std::string
const & resource)
187 : m_scheme(secure ?
"wss" :
"ws")
189 , m_resource(resource ==
"" ?
"/" : resource)
193 m_port = get_port_from_string(port,ec);
197 uri(std::string
const & scheme, std::string
const & host, uint16_t port,
198 std::string
const & resource)
201 , m_resource(resource ==
"" ?
"/" : resource)
203 , m_secure(scheme ==
"wss" || scheme ==
"https")
206 uri(std::string scheme, std::string
const & host, std::string
const & resource)
209 , m_resource(resource ==
"" ?
"/" : resource)
210 , m_port((scheme ==
"wss" || scheme ==
"https") ? uri_default_secure_port : uri_default_port)
211 , m_secure(scheme ==
"wss" || scheme ==
"https")
214 uri(std::string
const & scheme, std::string
const & host,
215 std::string
const & port, std::string
const & resource)
218 , m_resource(resource ==
"" ?
"/" : resource)
219 , m_secure(scheme ==
"wss" || scheme ==
"https")
222 m_port = get_port_from_string(port,ec);
226 bool get_valid()
const {
230 bool get_secure()
const {
234 std::string
const & get_scheme()
const {
238 std::string
const & get_host()
const {
242 std::string get_host_port()
const {
243 if (m_port == (m_secure ? uri_default_secure_port : uri_default_port)) {
247 p << m_host <<
":" << m_port;
252 std::string get_authority()
const {
254 p << m_host <<
":" << m_port;
258 uint16_t get_port()
const {
262 std::string get_port_str()
const {
268 std::string
const & get_resource()
const {
272 std::string str()
const {
275 s << m_scheme <<
"://" << m_host;
277 if (m_port != (m_secure ? uri_default_secure_port : uri_default_port)) {
293 std::size_t found = m_resource.find(
'?');
294 if (found != std::string::npos) {
295 return m_resource.substr(found + 1);
319 uint16_t get_port_from_string(std::string
const & port, lib::error_code &
322 ec = lib::error_code();
325 return (m_secure ? uri_default_secure_port : uri_default_port);
328 unsigned int t_port =
static_cast<unsigned int>(atoi(port.c_str()));
330 if (t_port > 65535) {
338 return static_cast<uint16_t
>(t_port);
341 std::string m_scheme;
343 std::string m_resource;
354 #endif // WEBSOCKETPP_URI_HPP
std::string get_query() const
Return the query portion.
Namespace for the WebSocket++ project.
lib::shared_ptr< uri > uri_ptr
Pointer to a URI.
static uint16_t const uri_default_port
Default port for ws://.
static uint16_t const uri_default_secure_port
Default port for wss://.