fix: 修复静态文件分发时,ContentType类型未设置的bug

This commit is contained in:
2020-12-18 11:18:43 +08:00
parent 3626a93e1a
commit 1cb2f76a5e
2 changed files with 2 additions and 1 deletions
+1 -1
View File
@@ -66,7 +66,7 @@ namespace MIN {
read(fd, fc->buf.base, fc->buf.len);
const char *suffix = strrchr(filepath, '.');
if (suffix) {
fc->contentType = getContentTypeStrBySuffix(suffix);
fc->contentType = getContentTypeStrBySuffix(suffix + 1);
}
} else if (S_ISDIR(fc->st.st_mode)) {
// DIR
+1
View File
@@ -111,6 +111,7 @@ namespace MIN {
response->content = (unsigned char *) fc->buf.base;
response->contentLength = fc->buf.len;
if (!fc->contentType.empty()) {
response->contentType = getMINHttpContentTypeEnumFromStr(fc->contentType);
response->headers["Content-Type"] = fc->contentType;
}
response->headers["Content-Length"] = std::to_string(response->contentLength);