From 61d116e2f34e21ae4b4c1789fa6f1654ed4f9c9b Mon Sep 17 00:00:00 2001 From: Thulinma Date: Tue, 8 May 2018 16:52:07 +0200 Subject: [PATCH] Added HTTP::URL::getExt function --- lib/http_parser.cpp | 8 ++++++++ lib/http_parser.h | 1 + 2 files changed, 9 insertions(+) diff --git a/lib/http_parser.cpp b/lib/http_parser.cpp index eed2acc9..1d45345b 100644 --- a/lib/http_parser.cpp +++ b/lib/http_parser.cpp @@ -158,6 +158,14 @@ uint32_t HTTP::URL::getDefaultPort() const{ return 0; } +/// Returns the file extension of the URL, or an empty string if none. +std::string HTTP::URL::getExt() const{ + if (path.rfind('.') == std::string::npos){ + return ""; + } + return path.substr(path.rfind('.')+1); +} + /// Returns the full URL in string format std::string HTTP::URL::getUrl() const{ std::string ret; diff --git a/lib/http_parser.h b/lib/http_parser.h index 37803b2f..cbb0e265 100644 --- a/lib/http_parser.h +++ b/lib/http_parser.h @@ -78,6 +78,7 @@ namespace HTTP{ URL(const std::string &url = ""); uint32_t getPort() const; uint32_t getDefaultPort() const; + std::string getExt() const; std::string getUrl() const; std::string getFilePath() const; std::string getBareUrl() const;