Class: Rack::Response

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

Overview

Required as Rack 1.5.x series removed the default content type of text/html for some unknown reason, something about “adhering to standards for HTTP 1.0 and 1.1 protocols” Was removed in this commit: github.com/rack/rack/commit/3623d04526b953a63bfb3e72de2d6920a042563f#L2L21

Instance Method Summary collapse

Constructor Details

#initialize(body = [], status = 200, header = {}) {|_self| ... } ⇒ Response

Returns a new instance of Response.

Yields:

  • (_self)

Yield Parameters:



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
# File 'lib/contour/fixes/rack.rb', line 21

def initialize(body=[], status=200, header={})
  @status = status.to_i
  @header = Utils::HeaderHash.new("Content-Type" => "text/html").merge(header) # This is the modified line that requires Content-Type set to text/html.

  @chunked = "chunked" == @header['Transfer-Encoding']
  @writer  = lambda { |x| @body << x }
  @block   = nil
  @length  = 0

  @body = []

  if body.respond_to? :to_str
    write body.to_str
  elsif body.respond_to?(:each)
    body.each { |part|
      write part.to_s
    }
  else
    raise TypeError, "stringable or iterable required"
  end

  yield self  if block_given?
end