Class: Response

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

Instance Method Summary collapse

Constructor Details

#initialize(code:, body: "") ⇒ Response

Returns a new instance of Response.



30
31
32
33
34
35
36
37
# File 'lib/http.rb', line 30

def initialize(code:, body: "")
  @code = code
  @response = 
    "HTTP/1.1 #{code}\r\n" +
    "Content-Length: #{body.size}\r\n" +
    "\r\n" +
    "#{body}\r\n"
end

Instance Method Details

#codeObject



43
44
45
# File 'lib/http.rb', line 43

def code 
  @code
end

#send(client) ⇒ Object



39
40
41
# File 'lib/http.rb', line 39

def send(client)
  client.write(@response)
end