Added port detection to URL parser, if not specified.
Before, if you parsed a URL using fr::URL, and a port wasn't explicitly mentioned in the URL, then fr::URL::get_port() would return an empty string. Now, it will try to detect the port type if none is specified. For example, URLs beginning with http, will be given a port of 80. This is to simplify usage of the URL class.
This commit is contained in:
parent
431f646bae
commit
64cce75bda
22
src/URL.cpp
22
src/URL.cpp
@ -63,6 +63,28 @@ namespace fr
|
|||||||
pos = (pos != std::string::npos) ? pos : url.size();
|
pos = (pos != std::string::npos) ? pos : url.size();
|
||||||
host = url.substr(parse_offset, pos - parse_offset);
|
host = url.substr(parse_offset, pos - parse_offset);
|
||||||
parse_offset = pos + 1;
|
parse_offset = pos + 1;
|
||||||
|
|
||||||
|
//Guess port based on scheme, if it's not explicitly provided.
|
||||||
|
switch(scheme)
|
||||||
|
{
|
||||||
|
case URL::HTTP:
|
||||||
|
port = "80";
|
||||||
|
break;
|
||||||
|
case URL::HTTPS:
|
||||||
|
port = "443";
|
||||||
|
break;
|
||||||
|
case URL::IRC:
|
||||||
|
port = "6697";
|
||||||
|
break;
|
||||||
|
case URL::FTP:
|
||||||
|
port = "21";
|
||||||
|
break;
|
||||||
|
case URL::SFTP:
|
||||||
|
port = "25";
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//Exit if done
|
//Exit if done
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user