Class: Jets::Controller::Response

Inherits:
Rack::Response
  • Object
show all
Defined in:
lib/jets/controller/response.rb

Overview

The response object. See Rack::Response and Rack::Response::Helpers for more info: rubydoc.info/github/rack/rack/master/Rack/Response rubydoc.info/github/rack/rack/master/Rack/Response/Helpers

Constant Summary collapse

DROP_BODY_RESPONSES =
[204, 304]

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.



10
11
12
13
# File 'lib/jets/controller/response.rb', line 10

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

Instance Method Details

#body=(value) ⇒ Object

TODO: unsure if we should even have these methods. We dont really use them.



16
17
18
19
# File 'lib/jets/controller/response.rb', line 16

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

#eachObject



21
22
23
# File 'lib/jets/controller/response.rb', line 21

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

#finishObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/jets/controller/response.rb', line 25

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 + p.bytesize }.to_s
  end

  [status.to_i, headers, result]
end