Class: Server::Request
- Inherits:
-
Object
- Object
- Server::Request
- Defined in:
- lib/server/request.rb
Instance Attribute Summary collapse
-
#request ⇒ Object
readonly
Returns the value of attribute request.
-
#socket ⇒ Object
readonly
Returns the value of attribute socket.
Instance Method Summary collapse
- #empty? ⇒ Boolean
-
#initialize(socket) ⇒ Request
constructor
A new instance of Request.
- #original_path ⇒ Object
- #params ⇒ Object
- #path ⇒ Object
- #to_s ⇒ Object
- #uri ⇒ Object
Constructor Details
#initialize(socket) ⇒ Request
Returns a new instance of Request.
7 8 9 10 |
# File 'lib/server/request.rb', line 7 def initialize(socket) @request = socket.gets @socket = socket end |
Instance Attribute Details
#request ⇒ Object (readonly)
Returns the value of attribute request.
5 6 7 |
# File 'lib/server/request.rb', line 5 def request @request end |
#socket ⇒ Object (readonly)
Returns the value of attribute socket.
5 6 7 |
# File 'lib/server/request.rb', line 5 def socket @socket end |
Instance Method Details
#empty? ⇒ Boolean
48 49 50 |
# File 'lib/server/request.rb', line 48 def empty? return @request ? false : true end |
#original_path ⇒ Object
40 41 42 |
# File 'lib/server/request.rb', line 40 def original_path URI.unescape(URI(uri).path) end |
#params ⇒ Object
16 17 18 19 |
# File 'lib/server/request.rb', line 16 def params query = URI(uri).query || '' @params ||= CGI::parse(query) end |
#path ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/server/request.rb', line 21 def path clean = [] # Split the path into components parts = original_path.split("/") parts.each do |part| # skip any empty or current directory (".") path components next if part.empty? || part == '.' # If the path component goes up one directory level (".."), # remove the last clean component. # Otherwise, add the component to the Array of clean components part == '..' ? clean.pop : clean << part end # return the web root joined to the clean path File.join(Dispatcher::WEB_ROOT, *clean) end |
#to_s ⇒ Object
44 45 46 |
# File 'lib/server/request.rb', line 44 def to_s @request end |
#uri ⇒ Object
12 13 14 |
# File 'lib/server/request.rb', line 12 def uri @request.split(" ")[1] end |