summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSebastien Douheret <sebastien.douheret@iot.bzh>2017-03-06 10:50:17 +0100
committerSebastien Douheret <sebastien.douheret@iot.bzh>2017-03-06 10:50:17 +0100
commit4291309fc7d24e11bb15378e980856fa00ac7da1 (patch)
tree5b3803aa902fee490f2a0cf328c586c98e098ac5
parente5d40e32d1f01b98c7344dae3707a38720e08666 (diff)
Add comments about always setting INFER_EXTENSION.
INFER_EXTENSION must always be set in order to provide right mimetypes for some files. For example mimetype for css files must be 'text/css' and not 'text/plain' as returned by libmagic. If mimetype is not correct, css files of HTML5 webapps will be not correctly interpreted resulting in a strange rendering in browser like Chrome. Change-Id: I7f0d9f97ede19308c87256f7850f5c51135827f3 Signed-off-by: Sebastien Douheret <sebastien.douheret@iot.bzh>
-rw-r--r--src/CMakeLists.txt1
-rw-r--r--src/afb-hreq.c6
2 files changed, 7 insertions, 0 deletions
diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt
index 0780cb4a..08a22901 100644
--- a/src/CMakeLists.txt
+++ b/src/CMakeLists.txt
@@ -23,6 +23,7 @@ endif(CMAKE_C_COMPILER_VERSION VERSION_LESS 4.9)
INCLUDE(FindPkgConfig)
ADD_DEFINITIONS(-DBINDING_INSTALL_DIR="${binding_install_dir}")
+# Always add INFER_EXTENSION (more details in afb-hreq.c)
ADD_DEFINITIONS(-DINFER_EXTENSION)
CHECK_INCLUDE_FILES(magic.h HAVE_MAGIC_H)
diff --git a/src/afb-hreq.c b/src/afb-hreq.c
index 5052cca9..00d4b0eb 100644
--- a/src/afb-hreq.c
+++ b/src/afb-hreq.c
@@ -274,6 +274,12 @@ static const char *mimetype_fd_name(int fd, const char *filename)
const char *result = NULL;
#if defined(INFER_EXTENSION)
+ /*
+ * Set some well-known extensions
+ * Note that it is mandatory for example for css files in order to provide
+ * right mimetype that must be text/css (otherwise chrome browser will not
+ * load correctly css file) while libmagic returns text/plain.
+ */
const char *extension = strrchr(filename, '.');
if (extension) {
static const char *const known[][2] = {