Class: RSence::Response
- Inherits:
-
Object
- Object
- RSence::Response
- Defined in:
- lib/rsence/http/response.rb
Overview
Classic WEBrick -compatible Response object for Rack. Implements only the methods used by the framework.
Defined Under Namespace
Classes: ResponseBody
Instance Method Summary collapse
- #[]=(header_key, header_val) ⇒ Object
- #body ⇒ Object
- #body=(body_data) ⇒ Object
- #body_bytes ⇒ Object
- #camelize(header_key) ⇒ Object
- #content_type ⇒ Object
- #content_type=(new_content_type) ⇒ Object
- #header ⇒ Object
-
#initialize ⇒ Response
constructor
A new instance of Response.
- #status ⇒ Object
- #status=(new_val) ⇒ Object
Constructor Details
#initialize ⇒ Response
Returns a new instance of Response.
31 32 33 34 35 36 37 38 39 |
# File 'lib/rsence/http/response.rb', line 31 def initialize @body = ResponseBody.new(1) @body[0] = '' @status = 200 @header = { 'Content-Type' => 'text/plain', 'Server' => 'RSence' } end |
Instance Method Details
#[]=(header_key, header_val) ⇒ Object
67 68 69 |
# File 'lib/rsence/http/response.rb', line 67 def []=(header_key,header_val) @header[camelize( header_key )] = header_val.to_s end |
#body ⇒ Object
44 45 46 |
# File 'lib/rsence/http/response.rb', line 44 def body @body end |
#body=(body_data) ⇒ Object
40 41 42 43 |
# File 'lib/rsence/http/response.rb', line 40 def body=(body_data) @body = ResponseBody.new(1) @body[0] = @body.sanitize_body_data( body_data ) end |
#body_bytes ⇒ Object
47 48 49 50 51 52 53 54 55 56 57 |
# File 'lib/rsence/http/response.rb', line 47 def body_bytes bytes = 0 @body.each do |part| if part.respond_to?(:to_s) bytes += part.to_s.bytesize else warn "body data part does not respond to to_s: #{part.inspect[0..100]}" end end return bytes.to_s end |
#camelize(header_key) ⇒ Object
64 65 66 |
# File 'lib/rsence/http/response.rb', line 64 def camelize( header_key ) header_key.capitalize.gsub(/\-([a-z])/) { '-'+$1.upcase } end |
#content_type ⇒ Object
61 62 63 |
# File 'lib/rsence/http/response.rb', line 61 def content_type @header['Content-Type'] end |
#content_type=(new_content_type) ⇒ Object
58 59 60 |
# File 'lib/rsence/http/response.rb', line 58 def content_type=(new_content_type) @header['Content-Type'] = new_content_type end |
#header ⇒ Object
76 77 78 |
# File 'lib/rsence/http/response.rb', line 76 def header @header end |
#status ⇒ Object
73 74 75 |
# File 'lib/rsence/http/response.rb', line 73 def status @status end |
#status=(new_val) ⇒ Object
70 71 72 |
# File 'lib/rsence/http/response.rb', line 70 def status=(new_val) @status = new_val.to_i end |