Class: Angus::Response

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

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.



3
4
5
6
# File 'lib/angus/response.rb', line 3

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

Instance Method Details

#body=(value) ⇒ Object



8
9
10
11
# File 'lib/angus/response.rb', line 8

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

#eachObject



13
14
15
# File 'lib/angus/response.rb', line 13

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

#finishObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/angus/response.rb', line 17

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, headers, result]
end