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;