From 64cce75bdabcd2bf1ea392e2f69ca65c124d1c84 Mon Sep 17 00:00:00 2001 From: Fred Nicolson Date: Wed, 24 May 2017 11:05:14 +0100 Subject: [PATCH] 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. --- src/URL.cpp | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/src/URL.cpp b/src/URL.cpp index efc18ea..ef0c859 100644 --- a/src/URL.cpp +++ b/src/URL.cpp @@ -63,6 +63,28 @@ namespace fr pos = (pos != std::string::npos) ? pos : url.size(); host = url.substr(parse_offset, pos - parse_offset); 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