Class: Server::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/server/request.rb

Instance Attribute Summary (collapse)

Instance Method Summary (collapse)

Constructor Details

- (Request) initialize(socket)

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

- (Object) request (readonly)

Returns the value of attribute request



5
6
7
# File 'lib/server/request.rb', line 5

def request
  @request
end

- (Object) socket (readonly)

Returns the value of attribute socket



5
6
7
# File 'lib/server/request.rb', line 5

def socket
  @socket
end

Instance Method Details

- (Boolean) empty?

Returns:

  • (Boolean)


48
49
50
# File 'lib/server/request.rb', line 48

def empty?
  return @request ? false : true
end

- (Object) original_path



40
41
42
# File 'lib/server/request.rb', line 40

def original_path
  URI.unescape(URI(uri).path)
end

- (Object) params



16
17
18
19
# File 'lib/server/request.rb', line 16

def params
  query = URI(uri).query || ''
  @params ||= CGI::parse(query)
end

- (Object) path



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

- (Object) to_s



44
45
46
# File 'lib/server/request.rb', line 44

def to_s
  @request
end

- (Object) uri



12
13
14
# File 'lib/server/request.rb', line 12

def uri
  @request.split(" ")[1]
end