-
Notifications
You must be signed in to change notification settings - Fork 13
Expand file tree
/
Copy pathProxyUri.cpp
More file actions
83 lines (74 loc) · 1.6 KB
/
ProxyUri.cpp
File metadata and controls
83 lines (74 loc) · 1.6 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
#include "ProxyUri.h"
#include <sstream>
Uri::Uri(std::string uri_string)
{
int seg = 0;
if ( (seg = uri_string.find("://")) != std::string::npos)
{
scheme = uri_string.substr(0, seg);
uri_string = uri_string.substr(seg+3);
}
else
scheme = "";
port = 0;
if ( (seg = uri_string.find_first_of("/")) != std::string::npos)
{
absuri = uri_string.substr(0, seg);
abspath = uri_string.substr(seg);
}
else
{
absuri = uri_string;
abspath = "";
}
if ( (seg = absuri.find_first_of(":")) != std::string::npos)
{
port = atoi(absuri.substr(seg+1).c_str());
absuri = absuri.substr(0, seg);
}
}
Uri::Uri():
scheme(""), absuri(""), port(0), abspath("")
{}
Uri::Uri(const Uri &uri)
{
scheme = uri.scheme;
absuri = uri.absuri;
port = uri.port;
abspath = uri.abspath;
}
Uri& Uri::operator= (const Uri& uri)
{
scheme = uri.scheme;
absuri = uri.absuri;
port = uri.port;
abspath = uri.abspath;
return *this;
}
std::string Uri::ToString(bool abs_uri) const
{
std::ostringstream ostr;
if (abs_uri)
{
if (scheme != "")
ostr << scheme + "://";
if (absuri != "")
{
ostr << absuri;
if (port != 0)
ostr << ":" << port;
}
}
if (abspath != "")
ostr << abspath;
return ostr.str();
}
std::string Uri::GetDomainName() const
{
std::string ostr = "";
if (scheme != "")
ostr += scheme + "://";
if (absuri != "")
ostr += absuri;
return ostr;
}