From ea319297764bd172100b3ea83fc52e12a06f0641 Mon Sep 17 00:00:00 2001 From: Christian Schmidt Date: Mon, 4 Sep 2023 09:46:33 +0200 Subject: [PATCH] Fix invalid Content-Type header for WebP images (#26773) --- config/initializers/mime_types.rb | 5 +++-- spec/models/media_attachment_spec.rb | 3 +++ 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/config/initializers/mime_types.rb b/config/initializers/mime_types.rb index b843c09ea..dde308cbc 100644 --- a/config/initializers/mime_types.rb +++ b/config/initializers/mime_types.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true -# Be sure to restart your server when you modify this file. - Mime::Type.register 'application/json', :json, %w(text/x-json application/jsonrequest application/jrd+json application/activity+json application/ld+json) Mime::Type.register 'text/xml', :xml, %w(application/xml application/atom+xml application/xrd+xml) + +# WebP is not defined in Rack 2.2. +Rack::Mime::MIME_TYPES['.webp'] = 'image/webp' diff --git a/spec/models/media_attachment_spec.rb b/spec/models/media_attachment_spec.rb index d57d43eda..6a82c8135 100644 --- a/spec/models/media_attachment_spec.rb +++ b/spec/models/media_attachment_spec.rb @@ -105,6 +105,9 @@ RSpec.describe MediaAttachment, paperclip_processing: true do # sets file extension expect(media.file_file_name).to end_with extension + + # Rack::Mime (used by PublicFileServerMiddleware) recognizes file extension + expect(Rack::Mime.mime_type(extension, nil)).to eq content_type end it 'saves media attachment with correct size metadata' do