mirror of
https://github.com/PurpleI2P/i2pd
synced 2024-11-09 15:50:26 +03:00
* HTTP.cpp : add comments, update test case
This commit is contained in:
parent
323f74c43a
commit
02ac638bd4
9
HTTP.cpp
9
HTTP.cpp
@ -73,6 +73,7 @@ namespace http {
|
||||
std::size_t pos_p = 0; /* < current parse position */
|
||||
std::size_t pos_c = 0; /* < work position */
|
||||
if(url.at(0) != '/' || pos_p > 0) {
|
||||
std::size_t pos_s = 0;
|
||||
/* schema */
|
||||
pos_c = url.find("://");
|
||||
if (pos_c != std::string::npos) {
|
||||
@ -80,9 +81,9 @@ namespace http {
|
||||
pos_p = pos_c + 3;
|
||||
}
|
||||
/* user[:pass] */
|
||||
pos_c = url.find('@', pos_p);
|
||||
std::size_t pos_slash = url.find('/', pos_p);
|
||||
if (pos_c != std::string::npos && (pos_slash == std::string::npos || pos_slash > pos_c)) {
|
||||
pos_s = url.find('/', pos_p); /* find first slash */
|
||||
pos_c = url.find('@', pos_p); /* find end of 'user' or 'user:pass' part */
|
||||
if (pos_c != std::string::npos && (pos_s == std::string::npos || pos_s > pos_c)) {
|
||||
std::size_t delim = url.find(':', pos_p);
|
||||
if (delim != std::string::npos && delim < pos_c) {
|
||||
user = url.substr(pos_p, delim - pos_p);
|
||||
@ -91,7 +92,7 @@ namespace http {
|
||||
} else {
|
||||
user = url.substr(pos_p, pos_c - pos_p);
|
||||
}
|
||||
pos_p = pos_c + 1;
|
||||
pos_p = pos_c + 1;
|
||||
}
|
||||
/* hostname[:port][/path] */
|
||||
pos_c = url.find_first_of(":/", pos_p);
|
||||
|
@ -104,6 +104,18 @@ int main() {
|
||||
assert(url->query == "");
|
||||
delete url;
|
||||
|
||||
url = new URL;
|
||||
assert(url->parse("http://user:password@site.com:84/asdasd/@17#frag") == true);
|
||||
assert(url->schema == "http");
|
||||
assert(url->user == "user");
|
||||
assert(url->pass == "password");
|
||||
assert(url->host == "site.com");
|
||||
assert(url->port == 84);
|
||||
assert(url->path == "/asdasd/@17");
|
||||
assert(url->query == "");
|
||||
assert(url->frag == "frag");
|
||||
delete url;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user