Class: Jubilee::Response

Inherits:
Object
  • Object
show all
Includes:
Const
Defined in:
lib/jubilee/response.rb

Constant Summary

Constants included from Const

Const::CGI_VER, Const::CONTENT_LENGTH, Const::GATEWAY_INTERFACE, Const::GET, Const::HTTP_10, Const::HTTP_11, Const::HTTP_ACCEPT, Const::HTTP_ACCEPT_ENCODING, Const::HTTP_ACCEPT_LANGUAGE, Const::HTTP_CONNECTION, Const::HTTP_COOKIE, Const::HTTP_HOST, Const::HTTP_USER_AGENT, Const::HTTP_VERSION, Const::JUBILEE_VERSION, Const::NEWLINE, Const::PATH_INFO, Const::POST, Const::QUERY_STRING, Const::RACK_INPUT, Const::REQUEST_METHOD, Const::REQUEST_PATH, Const::REQUEST_URI, Const::SERVER_NAME, Const::SERVER_PORT, Const::SERVER_PROTOCOL, Const::SERVER_SOFTWARE, Const::STATUS_WITH_NO_ENTITY_BODY, Const::TRANSFER_ENCODING

Instance Method Summary collapse

Constructor Details

#initialize(array) ⇒ Response

Returns a new instance of Response.



7
8
9
10
11
12
13
14
# File 'lib/jubilee/response.rb', line 7

def initialize(array)
  @status, @headers, @body = *array
  @status = @status.to_i
  @content_length = nil
  if @body.kind_of? Array and @body.size == 1
    @content_length = @body[0].bytesize
  end
end

Instance Method Details

#respond(response) ⇒ Object

See Rack::Utils


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

def respond(response)
  no_body = @status < 200 || STATUS_WITH_NO_ENTITY_BODY[@status]
  write_status(response)
  write_headers(response)
  if no_body
    response.end
  else 
    if @body.respond_to?(:to_path)
      response.send_file(@body.to_path)
    else
      write_body(response)
      response.end
    end
  end
rescue NativeException => e
  puts e
ensure
  @body.close if @body.respond_to?(:close)
end