Class: Rosendo::Response
- Inherits:
-
Object
- Object
- Rosendo::Response
- Defined in:
- lib/rosendo/response.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
Returns the value of attribute body.
-
#headers ⇒ Object
Returns the value of attribute headers.
-
#status ⇒ Object
Returns the value of attribute status.
Instance Method Summary collapse
- #header_lines ⇒ Object
-
#initialize(io) ⇒ Response
constructor
A new instance of Response.
- #respond ⇒ Object
- #status_line ⇒ Object
Constructor Details
#initialize(io) ⇒ Response
Returns a new instance of Response.
4 5 6 7 |
# File 'lib/rosendo/response.rb', line 4 def initialize(io) @io = io @headers = {} end |
Instance Attribute Details
#body ⇒ Object
Returns the value of attribute body.
3 4 5 |
# File 'lib/rosendo/response.rb', line 3 def body @body end |
#headers ⇒ Object
Returns the value of attribute headers.
3 4 5 |
# File 'lib/rosendo/response.rb', line 3 def headers @headers end |
#status ⇒ Object
Returns the value of attribute status.
3 4 5 |
# File 'lib/rosendo/response.rb', line 3 def status @status end |
Instance Method Details
#header_lines ⇒ Object
29 30 31 |
# File 'lib/rosendo/response.rb', line 29 def header_lines {'Content-Length' => body.size}.merge(@headers).map { |k, v| "#{k}: #{v}" }.join("\n") end |
#respond ⇒ Object
17 18 19 20 21 22 23 |
# File 'lib/rosendo/response.rb', line 17 def respond @io.puts status_line @io.puts header_lines @io.puts @io.write body # write instead of puts for no extra newline @io.close end |
#status_line ⇒ Object
25 26 27 |
# File 'lib/rosendo/response.rb', line 25 def status_line "HTTP/1.1 #{status}" end |