From 2a8b22558af17fd71b278c7821a94f661c203528 Mon Sep 17 00:00:00 2001 From: Aggelos Orfanakos Date: Sat, 13 Jul 2013 04:35:25 +0300 Subject: [PATCH] Don't set resp Content-Type for some status codes There must not be a Content-Type set when the Status is 1xx, 204, 205 or 304, otherwise Rack blows up with the following error: "Content-Type header found in 304 response, not allowed" --- .../lib/middleman-core/core_extensions/request.rb | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/middleman-core/lib/middleman-core/core_extensions/request.rb b/middleman-core/lib/middleman-core/core_extensions/request.rb index e5277840..99837644 100644 --- a/middleman-core/lib/middleman-core/core_extensions/request.rb +++ b/middleman-core/lib/middleman-core/core_extensions/request.rb @@ -291,8 +291,13 @@ module Middleman file = ::Rack::File.new nil file.path = resource.source_file response = file.serving(env) + status = response[0] response[1]['Content-Encoding'] = 'gzip' if %w(.svgz .gz).include?(resource.ext) - response[1]['Content-Type'] = resource.content_type || "application/octet-stream" + # Do not set Content-Type if status is 1xx, 204, 205 or 304, otherwise + # Rack will throw an error (500) + if !(100..199).include?(status) && ![204, 205, 304].include?(status) + response[1]['Content-Type'] = resource.content_type || "application/octet-stream" + end halt response end end