Skip to content

Commit

Permalink
Enhancement: extend drogon::ContentType for file handling (#1921)
Browse files Browse the repository at this point in the history
  • Loading branch information
Greisby authored Feb 9, 2024
1 parent 1a9ad1a commit aa04d33
Show file tree
Hide file tree
Showing 5 changed files with 416 additions and 305 deletions.
67 changes: 56 additions & 11 deletions lib/inc/drogon/HttpTypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -106,26 +106,71 @@ enum ContentType
CT_APPLICATION_X_JAVASCRIPT [[deprecated("use CT_TEXT_JAVASCRIPT")]],
CT_TEXT_JAVASCRIPT,
CT_TEXT_CSS,
CT_TEXT_XML,
CT_APPLICATION_XML,
CT_TEXT_CSV,
CT_TEXT_XML, // suggests human readable xml
CT_APPLICATION_XML, // suggest machine-to-machine xml
CT_TEXT_XSL,
CT_APPLICATION_WASM,
CT_APPLICATION_OCTET_STREAM,
CT_APPLICATION_X_FONT_TRUETYPE,
CT_APPLICATION_X_FONT_OPENTYPE,
CT_APPLICATION_FONT_WOFF,
CT_APPLICATION_FONT_WOFF2,
CT_APPLICATION_VND_MS_FONTOBJ,
CT_APPLICATION_GZIP,
CT_APPLICATION_JAVA_ARCHIVE,
CT_APPLICATION_PDF,
CT_IMAGE_SVG_XML,
CT_IMAGE_PNG,
CT_IMAGE_WEBP,
CT_APPLICATION_MSWORD,
CT_APPLICATION_MSWORDX,
CT_APPLICATION_VND_MS_FONTOBJ,
CT_APPLICATION_VND_RAR,
CT_APPLICATION_XHTML,
CT_APPLICATION_X_7Z,
CT_APPLICATION_X_BZIP,
CT_APPLICATION_X_BZIP2,
CT_APPLICATION_X_HTTPD_PHP,
CT_APPLICATION_X_FONT_TRUETYPE,
CT_APPLICATION_X_FONT_OPENTYPE,
CT_APPLICATION_X_TAR,
CT_APPLICATION_X_TGZ,
CT_APPLICATION_X_XZ,
CT_APPLICATION_ZIP,
CT_AUDIO_AAC,
CT_AUDIO_AC3,
CT_AUDIO_AIFF,
CT_AUDIO_FLAC,
CT_AUDIO_MATROSKA,
CT_AUDIO_MPEG,
CT_AUDIO_MPEG4,
CT_AUDIO_OGG,
CT_AUDIO_WAVE,
CT_AUDIO_WEBM,
CT_AUDIO_X_APE,
CT_AUDIO_X_MS_WMA,
CT_AUDIO_X_TTA,
CT_AUDIO_X_WAVPACK,
CT_IMAGE_APNG,
CT_IMAGE_AVIF,
CT_IMAGE_JPG,
CT_IMAGE_BMP,
CT_IMAGE_GIF,
CT_IMAGE_XICON,
CT_IMAGE_ICNS,
CT_IMAGE_BMP,
CT_IMAGE_JPG,
CT_IMAGE_JP2,
CT_IMAGE_PNG,
CT_IMAGE_SVG_XML,
CT_IMAGE_TIFF,
CT_IMAGE_WEBP,
CT_IMAGE_X_MNG,
CT_IMAGE_X_TGA,
CT_IMAGE_XICON,
CT_VIDEO_APG,
CT_VIDEO_AV1,
CT_VIDEO_QUICKTIME,
CT_VIDEO_MATROSKA,
CT_VIDEO_MP4,
CT_VIDEO_MPEG,
CT_VIDEO_MPEG2TS,
CT_VIDEO_OGG,
CT_VIDEO_WEBM,
CT_VIDEO_X_M4V,
CT_VIDEO_X_MSVIDEO,
CT_MULTIPART_FORM_DATA,
CT_CUSTOM
};
Expand Down
3 changes: 3 additions & 0 deletions lib/src/HttpFileImpl.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,9 @@ class HttpFileImpl
/// Return the type of file.
FileType getFileType() const noexcept
{
auto ft = drogon::getFileType(contentType_);
if ((ft != FT_UNKNOWN) && (ft != FT_CUSTOM))
return ft;
return parseFileType(getFileExtension());
}

Expand Down
Loading

0 comments on commit aa04d33

Please sign in to comment.