class Server::Request
Attributes
request[R]
socket[R]
Public Class Methods
new(socket)
click to toggle source
# File lib/server/request.rb, line 7 def initialize(socket) @request = socket.gets @socket = socket end
Public Instance Methods
empty?()
click to toggle source
# File lib/server/request.rb, line 48 def empty? return @request ? false : true end
original_path()
click to toggle source
# File lib/server/request.rb, line 40 def original_path URI.unescape(URI(uri).path) end
params()
click to toggle source
# File lib/server/request.rb, line 16 def params query = URI(uri).query || '' @params ||= CGI::parse(query) end
path()
click to toggle source
# 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()
click to toggle source
# File lib/server/request.rb, line 44 def to_s @request end
uri()
click to toggle source
# File lib/server/request.rb, line 12 def uri @request.split(" ")[1] end