Class: Ocular::Inputs::HTTP::Input::Response

Inherits:
Rack::Response
  • Object
show all
Defined in:
lib/ocular/inputs/http_input.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, 205, 304]

Instance Method Summary collapse

Constructor Details

#initializeResponse

Returns a new instance of Response.



213
214
215
216
# File 'lib/ocular/inputs/http_input.rb', line 213

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

Instance Method Details

#body=(value) ⇒ Object



218
219
220
221
# File 'lib/ocular/inputs/http_input.rb', line 218

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

#eachObject



223
224
225
# File 'lib/ocular/inputs/http_input.rb', line 223

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

#finishObject



227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
# File 'lib/ocular/inputs/http_input.rb', line 227

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