Class: Pronghorn::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/pronghorn/response.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status = 200, headers = {"Content-Type" => "text/plain"}, body = [""]) ⇒ Response

Returns a new instance of Response.



10
11
12
13
14
# File 'lib/pronghorn/response.rb', line 10

def initialize(status = 200, headers = {"Content-Type" => "text/plain"}, body = [""])
  @status = status
  @headers = headers
  @body = body
end

Instance Attribute Details

#bodyObject

Returns the value of attribute body.



6
7
8
# File 'lib/pronghorn/response.rb', line 6

def body
  @body
end

#headersObject

Returns the value of attribute headers.



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

def headers
  @headers
end

#statusObject

Returns the value of attribute status.



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

def status
  @status
end

Instance Method Details

#closeObject



24
25
26
# File 'lib/pronghorn/response.rb', line 24

def close
  @body.close if @body.respond_to?(:close)
end

#each {|head| ... } ⇒ Object

Yields:



28
29
30
31
# File 'lib/pronghorn/response.rb', line 28

def each
  yield head
  @body.each { |chunk| yield chunk }
end

#headObject



16
17
18
19
20
21
22
# File 'lib/pronghorn/response.rb', line 16

def head
  lines = []
  lines << "HTTP/1.1 #{@status}\r\n"
  lines += generate_header_lines(@headers)
  lines << "\r\n"
  lines.join
end