Class: Rakie::HttpResponse

Inherits:
Object
  • Object
show all
Includes:
Proto
Defined in:
lib/rakie/http_proto.rb

Defined Under Namespace

Classes: Head

Constant Summary collapse

PARSE_HEAD =
0
PARSE_HEADERS =
1
PARSE_CONTENT =
2

Constants included from Proto

Proto::PARSE_BEGIN

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Proto

#parse, #parse_offset, #parse_offset=, #parse_state, #parse_state=, #parse_status, #to_s

Constructor Details

#initializeHttpResponse

Returns a new instance of HttpResponse.



174
175
176
177
178
# File 'lib/rakie/http_proto.rb', line 174

def initialize
  @head = Head.new
  @headers = {}
  @content = ''
end

Instance Attribute Details

#contentObject

Returns the value of attribute content.



162
163
164
# File 'lib/rakie/http_proto.rb', line 162

def content
  @content
end

#headObject

Returns the value of attribute head.



162
163
164
# File 'lib/rakie/http_proto.rb', line 162

def head
  @head
end

#headersObject

Returns the value of attribute headers.



162
163
164
# File 'lib/rakie/http_proto.rb', line 162

def headers
  @headers
end

Instance Method Details

#serializeObject



180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/rakie/http_proto.rb', line 180

def serialize
  data = ""

  data += "#{head.version} #{head.status} #{head.message}"
  data += "\r\n"

  headers_list = []
  headers.each do |k, v|
    headers_list << "#{k}: #{v}"
  end

  data += headers_list.join("\r\n")
  data += "\r\n\r\n"

  data += content
end