Class: Midori::Response
- Inherits:
-
Object
- Object
- Midori::Response
- Defined in:
- lib/midori/response.rb
Overview
Class for midori response
Instance Attribute Summary collapse
-
#body ⇒ String
HTTP response body.
-
#header ⇒ Hash
HTTP response header.
-
#status ⇒ String
HTTP response status.
Instance Method Summary collapse
-
#generate_header ⇒ String
Generate header string from hash.
-
#initialize(options = {}) ⇒ Response
constructor
Init a Response.
-
#to_s ⇒ String
Convert response to raw string.
Constructor Details
#initialize(options = {}) ⇒ Response
Init a Response
14 15 16 17 18 19 |
# File 'lib/midori/response.rb', line 14 def initialize( = {}) code = [:status] || 200 @status = Midori::Const::STATUS_CODE[code] @header = [:header] || Midori::Const::DEFAULT_HEADER.clone @body = [:body] || '' end |
Instance Attribute Details
#header ⇒ Hash
HTTP response header
6 7 8 |
# File 'lib/midori/response.rb', line 6 def header @header end |
#status ⇒ String
HTTP response status
6 7 8 |
# File 'lib/midori/response.rb', line 6 def status @status end |
Instance Method Details
#generate_header ⇒ String
Generate header string from hash
23 24 25 26 27 |
# File 'lib/midori/response.rb', line 23 def generate_header @header.map do |key, value| "#{key}: #{value}\r\n" end.join end |
#to_s ⇒ String
Convert response to raw string
31 32 33 |
# File 'lib/midori/response.rb', line 31 def to_s "HTTP/1.1 #{@status}\r\n#{generate_header}\r\n#{@body}" end |