X-Git-Url: https://gerrit.automotivelinux.org/gerrit/gitweb?a=blobdiff_plain;ds=sidebyside;f=src%2Fafb-hreq.c;h=474b90e8f2adecdbf4a1a202c3ca9ba011fa6e08;hb=a93623ba9a6914f381449205873a1d879deaee88;hp=087a27ceb7e6c56b94b57e1206c601386f3a9839;hpb=f113d2b31333538f5784de5ee5f02bc19cc603e4;p=src%2Fapp-framework-binder.git diff --git a/src/afb-hreq.c b/src/afb-hreq.c index 087a27ce..474b90e8 100644 --- a/src/afb-hreq.c +++ b/src/afb-hreq.c @@ -184,7 +184,34 @@ static const char *magic_mimetype_fd(int fd) #endif - +static const char *mimetype_fd_name(int fd, const char *filename) +{ + const char *result = NULL; + +#if defined(INFER_EXTENSION) + const char *extension = strrchr(filename, '.'); + if (extension) { + static const char *const known[][2] = { + { ".js", "text/javascript" }, + { ".html", "text/html" }, + { NULL, NULL } + }; + int i = 0; + while (known[i][0]) { + if (!strcasecmp(extension, known[i][0])) { + result = known[i][1]; + break; + } + i++; + } + } +#endif +#if defined(USE_MAGIC_MIME_TYPE) + if (result == NULL) + result = magic_mimetype_fd(fd); +#endif + return result; +} void afb_hreq_free(struct afb_hreq *hreq) { @@ -257,6 +284,7 @@ int afb_hreq_reply_file_if_exist(struct afb_hreq *hreq, int dirfd, const char *f char etag[1 + 2 * sizeof(int)]; const char *inm; struct MHD_Response *response; + const char *mimetype; /* Opens the file or directory */ if (filename[0]) { @@ -336,14 +364,10 @@ int afb_hreq_reply_file_if_exist(struct afb_hreq *hreq, int dirfd, const char *f response = MHD_create_response_from_fd((size_t) st.st_size, fd); status = MHD_HTTP_OK; -#if defined(USE_MAGIC_MIME_TYPE) /* set the type */ - { - const char *mimetype = magic_mimetype_fd(fd); - if (mimetype != NULL) - MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, mimetype); - } -#endif + mimetype = mimetype_fd_name(fd, filename); + if (mimetype != NULL) + MHD_add_response_header(response, MHD_HTTP_HEADER_CONTENT_TYPE, mimetype); } /* fills the value and send */ @@ -562,7 +586,7 @@ struct AFB_clientCtx *afb_hreq_context(struct afb_hreq *hreq) uuid = afb_hreq_get_argument(hreq, uuid_arg); if (uuid == NULL) uuid = afb_hreq_get_cookie(hreq, uuid_cookie); - hreq->context = ctxClientGet(uuid); + hreq->context = ctxClientGetForUuid(uuid); } return hreq->context; }