Skip to content

Commit 7a8fa42

Browse files
Add HTTP content-type for WebP and AVIF (#229)
* Add HTTP content-type for WebP and AVIF This PR extends the _setContentTypeFromPath method to correctly identify and assign Content-Type headers for .webp (image/webp) and .avif (image/avif) files. Additionally, all HTTP headers are now formatted in Title Case, aligning with RFC 7231 and improving consistency across responses. Developers are encouraged to adopt AVIF or WebP formats over legacy image types such as GIF, PNG, or JPEG. Both formats are fully supported by all major modern browsers and typically offer significant file size reductions (often 50% or more) without perceptible quality loss. Conversion of assets is straightforward using tools like squoosh.app (free and online), which supports batch optimization and visual comparisons across formats. * ci(pre-commit): Apply automatic fixes * revert Title Case changes in literals.h me-no-dev requests fulfilled: - please do not change the styling - to split it in two PRs --------- Co-authored-by: pre-commit-ci-lite[bot] <117423508+pre-commit-ci-lite[bot]@users.noreply.github.com>
1 parent 42d2aad commit 7a8fa42

File tree

2 files changed

+8
-0
lines changed

2 files changed

+8
-0
lines changed

src/WebResponses.cpp

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -662,6 +662,10 @@ void AsyncFileResponse::_setContentTypeFromPath(const String &path) {
662662
_contentType = T_image_svg_xml;
663663
} else if (strcmp(dot, T__jpg) == 0) {
664664
_contentType = T_image_jpeg;
665+
} else if (strcmp(dot, T__webp) == 0) {
666+
_contentType = T_image_webp;
667+
} else if (strcmp(dot, T__avif) == 0) {
668+
_contentType = T_image_avif;
665669
} else if (strcmp(dot, T__gif) == 0) {
666670
_contentType = T_image_gif;
667671
} else if (strcmp(dot, T__woff2) == 0) {

src/literals.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ static constexpr const char *T_RCT_EVENT = "RCT_EVENT";
106106
static constexpr const char *T_ERROR = "ERROR";
107107

108108
// extensions & MIME-Types
109+
static constexpr const char *T__avif = ".avif";
109110
static constexpr const char *T__css = ".css";
110111
static constexpr const char *T__eot = ".eot";
111112
static constexpr const char *T__gif = ".gif";
@@ -120,6 +121,7 @@ static constexpr const char *T__pdf = ".pdf";
120121
static constexpr const char *T__png = ".png";
121122
static constexpr const char *T__svg = ".svg";
122123
static constexpr const char *T__ttf = ".ttf";
124+
static constexpr const char *T__webp = ".webp";
123125
static constexpr const char *T__woff = ".woff";
124126
static constexpr const char *T__woff2 = ".woff2";
125127
static constexpr const char *T__xml = ".xml";
@@ -134,10 +136,12 @@ static constexpr const char *T_font_eot = "font/eot";
134136
static constexpr const char *T_font_ttf = "font/ttf";
135137
static constexpr const char *T_font_woff = "font/woff";
136138
static constexpr const char *T_font_woff2 = "font/woff2";
139+
static constexpr const char *T_image_avif = "image/avif";
137140
static constexpr const char *T_image_gif = "image/gif";
138141
static constexpr const char *T_image_jpeg = "image/jpeg";
139142
static constexpr const char *T_image_png = "image/png";
140143
static constexpr const char *T_image_svg_xml = "image/svg+xml";
144+
static constexpr const char *T_image_webp = "image/webp";
141145
static constexpr const char *T_image_x_icon = "image/x-icon";
142146
static constexpr const char *T_text_css = "text/css";
143147
static constexpr const char *T_text_event_stream = "text/event-stream";

0 commit comments

Comments
 (0)