Class: EResponse

Inherits:
Rack::Response
  • Object
show all
Defined in:
lib/e-core/instance/response.rb

Overview

The response object. See Rack::Response and Rack::ResponseHelpers for more info: rack.rubyforge.org/doc/classes/Rack/Response.html rack.rubyforge.org/doc/classes/Rack/Response/Helpers.html

Instance Method Summary collapse

Constructor Details

#initializeEResponse

kindly borrowed from Sinatra



5
6
7
8
# File 'lib/e-core/instance/response.rb', line 5

def initialize(*)
  super
  headers['Content-Type'] ||= 'text/html'
end

Instance Method Details

#body=(value) ⇒ Object



10
11
12
13
# File 'lib/e-core/instance/response.rb', line 10

def body=(value)
  value = value.body while Rack::Response === value
  @body = String === value ? [value.to_str] : value
end

#eachObject



15
16
17
# File 'lib/e-core/instance/response.rb', line 15

def each
  block_given? ? super : enum_for(:each)
end

#finishObject



19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/e-core/instance/response.rb', line 19

def finish
  result = body

  if 
    headers.delete "Content-Length"
    headers.delete "Content-Type"
  end

  if drop_body?
    close
    result = []
  end

  if calculate_content_length?
    # if some other code has already set Content-Length, don't muck with it
    # currently, this would be the static file-handler
    headers["Content-Length"] = body.inject(0) { |l, p| l + Rack::Utils.bytesize(p) }.to_s
  end

  [status.to_i, header, result]
end