lib/roda.rb in roda-2.18.0 vs lib/roda.rb in roda-2.19.0

- old
+ new

@@ -865,10 +865,11 @@ end # Instance methods for RodaResponse module ResponseMethods CONTENT_LENGTH = "Content-Length".freeze + CONTENT_TYPE = "Content-Type".freeze DEFAULT_HEADERS = {"Content-Type" => "text/html".freeze}.freeze LOCATION = "Location".freeze # The body for the current response. attr_reader :body @@ -930,13 +931,20 @@ # # => [200, # # {'Content-Type'=>'text/html', 'Content-Length'=>'0'}, # # []] def finish b = @body - s = (@status ||= b.empty? ? 404 : default_status) + empty = b.empty? + s = (@status ||= empty ? 404 : default_status) set_default_headers h = @headers - h[CONTENT_LENGTH] ||= @length.to_s + + if empty && (s == 304 || s == 204 || s == 205 || (s >= 100 && s <= 199)) + h.delete(CONTENT_TYPE) + else + h[CONTENT_LENGTH] ||= @length.to_s + end + [s, h, b] end # Return the rack response array using a given body. Assumes a # 200 response status unless status has been explicitly set,