Class: Rack::ContentType

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/content_type.rb

Overview

Sets the Content-Type header on responses which don’t have one.

Builder Usage:

use Rack::ContentType, "text/plain"

When no content type argument is provided, “text/html” is assumed.

Instance Method Summary collapse

Constructor Details

#initialize(app, content_type = "text/html") ⇒ ContentType

Returns a new instance of ContentType.



12
13
14
# File 'lib/rack/content_type.rb', line 12

def initialize(app, content_type = "text/html")
  @app, @content_type = app, content_type
end

Instance Method Details

#call(env) ⇒ Object



16
17
18
19
20
21
# File 'lib/rack/content_type.rb', line 16

def call(env)
  status, headers, body = @app.call(env)
  headers = Utils::HeaderHash.new(headers)
  headers['Content-Type'] ||= @content_type
  [status, headers.to_hash, body]
end