Class: Adelnor::Request
- Inherits:
-
Object
- Object
- Adelnor::Request
- Defined in:
- lib/adelnor/request.rb
Instance Attribute Summary collapse
-
#body ⇒ Object
readonly
Returns the value of attribute body.
-
#content_length ⇒ Object
readonly
Returns the value of attribute content_length.
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#path_info ⇒ Object
readonly
Returns the value of attribute path_info.
-
#query_string ⇒ Object
readonly
Returns the value of attribute query_string.
-
#request_method ⇒ Object
readonly
Returns the value of attribute request_method.
-
#request_path ⇒ Object
readonly
Returns the value of attribute request_path.
Class Method Summary collapse
Instance Method Summary collapse
- #build ⇒ Object
-
#initialize(message) ⇒ Request
constructor
A new instance of Request.
- #parse_body!(client) ⇒ Object
Constructor Details
#initialize(message) ⇒ Request
Returns a new instance of Request.
8 9 10 11 12 13 14 |
# File 'lib/adelnor/request.rb', line 8 def initialize() @message = @request_method = @request_path = nil @headers = {} @body = '' end |
Instance Attribute Details
#body ⇒ Object (readonly)
Returns the value of attribute body.
5 6 7 |
# File 'lib/adelnor/request.rb', line 5 def body @body end |
#content_length ⇒ Object (readonly)
Returns the value of attribute content_length.
5 6 7 |
# File 'lib/adelnor/request.rb', line 5 def content_length @content_length end |
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
5 6 7 |
# File 'lib/adelnor/request.rb', line 5 def headers @headers end |
#path_info ⇒ Object (readonly)
Returns the value of attribute path_info.
5 6 7 |
# File 'lib/adelnor/request.rb', line 5 def path_info @path_info end |
#query_string ⇒ Object (readonly)
Returns the value of attribute query_string.
5 6 7 |
# File 'lib/adelnor/request.rb', line 5 def query_string @query_string end |
#request_method ⇒ Object (readonly)
Returns the value of attribute request_method.
5 6 7 |
# File 'lib/adelnor/request.rb', line 5 def request_method @request_method end |
#request_path ⇒ Object (readonly)
Returns the value of attribute request_path.
5 6 7 |
# File 'lib/adelnor/request.rb', line 5 def request_path @request_path end |
Class Method Details
.build(*args) ⇒ Object
16 17 18 |
# File 'lib/adelnor/request.rb', line 16 def self.build(*args) new(*args).build end |
Instance Method Details
#build ⇒ Object
20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/adelnor/request.rb', line 20 def build lines = @message.split(/\r\n/) headline = lines.shift return self unless headline parse_headline!(headline) parse_headers!(lines) self end |
#parse_body!(client) ⇒ Object
32 33 34 35 36 37 |
# File 'lib/adelnor/request.rb', line 32 def parse_body!(client) @content_length = @headers['Content-Length'] return unless @content_length @body = client.read(@content_length.to_i) end |