accept urls without trailing '/'

This commit is contained in:
john30
2018-02-04 16:18:10 +01:00
parent cf05b63aa3
commit f2f70d400a
+10 -6
View File
@@ -20,7 +20,6 @@
#include <cstring> #include <cstring>
#include <cstdlib> #include <cstdlib>
#include <sstream> #include <sstream>
#include <ios>
namespace ebusd { namespace ebusd {
@@ -40,13 +39,18 @@ bool HttpClient::parseUrl(const string& url, string& proto, string& host, uint16
return false; return false;
} }
size_t pos = url.find('/', hostPos); size_t pos = url.find('/', hostPos);
if (pos == string::npos || pos == hostPos) { if (pos == hostPos) {
return false; return false;
} }
host = url.substr(hostPos, pos - hostPos); if (pos == string::npos) {
uri = url.substr(pos); host = url.substr(hostPos);
if (uri[uri.length()-1] != '/') { uri = "/";
uri += "/"; } else {
host = url.substr(hostPos, pos - hostPos);
uri = url.substr(pos);
if (uri[uri.length()-1] != '/') {
uri += "/";
}
} }
pos = host.find(':'); pos = host.find(':');
if (pos == 0) { if (pos == 0) {