Added helpers for detecting mimetype

fr::Http::get_mimetype(filename) will return the mimetype of a given filename or file extention. This should be used to set the 'content-type' header when creating fr::HttpResponses.
This commit is contained in:
Fred Nicolson
2017-05-07 10:44:33 +01:00
parent 53ab6e2090
commit 7ea87cced8
2 changed files with 726 additions and 0 deletions
+12
View File
@@ -234,6 +234,14 @@ namespace fr
*/
static std::string url_decode(const std::string &str);
/*!
* Gets the mimetype of a given filename, or file extention.
*
* @param filename The filename, or file extention to find the mime type of
* @return The mime type. Returns 'application/octet-stream' if it couldn't be found.
*/
const std::string &get_mimetype(const std::string &filename);
protected:
/*!
* Splits a string by new line. Ignores escaped \n's
@@ -282,6 +290,10 @@ namespace fr
RequestType request_type;
std::string uri;
RequestStatus status;
private:
static std::unordered_map<std::string, std::string> mime_types;
void load_mimetypes();
};
}