summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-12-24 07:45:34 +0100
committerNicolas "Pixel" Noble <pixel@nobis-crew.org>2013-12-24 07:45:34 +0100
commitd2938865f2421e160adc18e86dd7813278035c70 (patch)
tree94c1ce6850269acbb54ffb488a2172c3ac763028
parentdf8dd99434e5918a7506d888877d070356111d43 (diff)
Adding proper mime/type support.
-rw-r--r--includes/Http.h2
-rw-r--r--src/Http.cc18
2 files changed, 20 insertions, 0 deletions
diff --git a/includes/Http.h b/includes/Http.h
index fae2ad9..00db23a 100644
--- a/includes/Http.h
+++ b/includes/Http.h
@@ -16,6 +16,8 @@ namespace Http {
const char * getStatusMsg(int httpStatus);
+const char * getContentType(const String & extension);
+
typedef std::map<String, String> StringMap;
typedef std::map<String, IO<Handle> > FileList;
diff --git a/src/Http.cc b/src/Http.cc
index 4e3e2a6..4ae240e 100644
--- a/src/Http.cc
+++ b/src/Http.cc
@@ -1,3 +1,5 @@
+#include <map>
+
#include "Http.h"
const char * Balau::Http::getStatusMsg(int httpStatus) {
@@ -46,3 +48,19 @@ const char * Balau::Http::getStatusMsg(int httpStatus) {
}
return "Unknown HTTP code";
}
+
+static std::map<Balau::String, const char *> s_mimeMap {
+ std::make_pair("css", "text/css"),
+ std::make_pair("html", "text/html"),
+ std::make_pair("js", "application/javascript"),
+ std::make_pair("json", "application/json"),
+ std::make_pair("png", "image/png"),
+ std::make_pair("gif", "image/gif"),
+};
+
+const char * Balau::Http::getContentType(const String & extension) {
+ auto t = s_mimeMap.find(extension);
+ if (t == s_mimeMap.end())
+ return "application/octet-stream";
+ return t->second;
+}