Class: Knod::Request
- Inherits:
-
Object
- Object
- Knod::Request
- Defined in:
- lib/knod/request.rb
Instance Attribute Summary collapse
-
#headers ⇒ Object
readonly
Returns the value of attribute headers.
-
#request_line ⇒ Object
readonly
Returns the value of attribute request_line.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
- #body ⇒ Object
- #content_length ⇒ Object
- #content_type ⇒ Object
-
#initialize(socket) ⇒ Request
constructor
A new instance of Request.
- #method ⇒ Object
- #parse_request ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(socket) ⇒ Request
Returns a new instance of Request.
5 6 7 8 9 |
# File 'lib/knod/request.rb', line 5 def initialize(socket) @socket = socket @request_line = socket.gets parse_request end |
Instance Attribute Details
#headers ⇒ Object (readonly)
Returns the value of attribute headers.
3 4 5 |
# File 'lib/knod/request.rb', line 3 def headers @headers end |
#request_line ⇒ Object (readonly)
Returns the value of attribute request_line.
3 4 5 |
# File 'lib/knod/request.rb', line 3 def request_line @request_line end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
3 4 5 |
# File 'lib/knod/request.rb', line 3 def socket @socket end |
Instance Method Details
#body ⇒ Object
38 39 40 |
# File 'lib/knod/request.rb', line 38 def body @body ||= socket.read(content_length) end |
#content_length ⇒ Object
22 23 24 |
# File 'lib/knod/request.rb', line 22 def content_length headers['Content-Length'].to_i end |
#content_type ⇒ Object
26 27 28 |
# File 'lib/knod/request.rb', line 26 def content_type headers['Content-Type'] end |
#method ⇒ Object
34 35 36 |
# File 'lib/knod/request.rb', line 34 def method @verb ||= request_line.split.first.upcase end |
#parse_request ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/knod/request.rb', line 11 def parse_request headers = {} loop do line = socket.gets break if line == "\r\n" name, value = line.strip.split(': ') headers[name] = value end @headers = headers end |
#uri ⇒ Object
30 31 32 |
# File 'lib/knod/request.rb', line 30 def uri @uri ||= request_line.split[1] end |