FazBrowse GitHub Viewer
|
Trending
|
URL:
|
Home
Tools:
[Download Repo ZIP]
[View Raw Code]
[Original HTTPS Page]
expresscpp/src/url.cpp at master · expresscpp/expresscpp · GitHub
expresscpp
/
expresscpp
Public
Notifications
You must be signed in to change notification settings
Fork
15
Star
96
Code
Issues
5
Pull requests
2
Actions
Projects
Security and quality
0
Insights
Additional navigation options
Code
Issues
Pull requests
Actions
Projects
Security and quality
Insights
Expand file tree
Breadcrumbs
expresscpp
/
src
/
url.cpp
Copy path
More file actions
More file actions
Latest commit
History
History
History
32 lines (28 loc) · 1.2 KB
Breadcrumbs
expresscpp
/
src
/
url.cpp
Copy path
File metadata and controls
32 lines (28 loc) · 1.2 KB
Raw
Copy raw file
Download raw file
Open symbols panel
Edit and raw actions
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
#
include
"
expresscpp/url.hpp
"
#
include
<
regex
>
#
include
<
string
>
#
include
"
boost/algorithm/string.hpp
"
namespace
expresscpp
{
ParsedURI
parseURI
(
const
std::string& url) {
ParsedURI result;
auto
value_or = [](
const
std::string& value, std::string&& deflt) -> std::string {
return
(value.
empty
() ? deflt : value);
};
//
Note: only "http", "https", "ws", and "wss" protocols are supported
static
const
std::regex
PARSE_URL
{
R"(
(([httpsw]{2,5})://)?([^/ :]+)(:(\d+))?(/([^ ?]+)?)?/?\??([^/ ]+\=[^/ ]+)?
)"
,
std::regex_constants::ECMAScript | std::regex_constants::icase};
std::smatch match;
if
(
std::regex_match
(url, match,
PARSE_URL
) && match.
size
() ==
9
) {
result.
protocol
=
value_or
(
boost::algorithm::to_lower_copy
(
std::string
(match[
2
])),
"
http
"
);
result.
domain
= match[
3
];
const
bool
is_sequre_protocol = (result.
protocol
==
"
https
"
|| result.
protocol
==
"
wss
"
);
result.
port
=
value_or
(match[
5
], (is_sequre_protocol) ?
"
443
"
:
"
80
"
);
result.
resource
=
value_or
(match[
6
],
"
/
"
);
result.
query
= match[
8
];
if
(result.
domain
.
empty
()) {
throw
std::invalid_argument
(
"
domain cannot be empty
"
);
}
}
return
result;
}
}
//
namespace expresscpp
Back
|
FazBrowse Home
|
New Git URL