teehee :3
This commit is contained in:
parent
2ce8a9c28b
commit
0f893c1d83
27 changed files with 3905 additions and 68 deletions
|
|
@ -1,13 +1,18 @@
|
|||
# Request class used as instance object of an incoming TCP request to manage that request. Splits the request into it's method, resource, version, headers and params to be read by the router.
|
||||
class Request
|
||||
attr_reader :method, :resource, :version, :headers, :params
|
||||
|
||||
# @param input [String] the string of the request
|
||||
def initialize(input)
|
||||
variable_definer(input)
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def variable_definer(input) ##Defines required class variables by splitting up the input text
|
||||
# Defines required class variables by splitting up the input text
|
||||
#
|
||||
# @param input [String] the string of the request
|
||||
def variable_definer(input)
|
||||
rows = input.split(/\r\n/)
|
||||
@method, @resource, @version = rows[0].split(' ')
|
||||
@headers, @params = {}, {}
|
||||
|
|
@ -25,6 +30,10 @@ class Request
|
|||
end
|
||||
end
|
||||
|
||||
# Reorganizes the information in the header based on the format
|
||||
#
|
||||
# @param rows [Array] A list of the rows in the header
|
||||
# @param limit [Int] The limit where the header ends.
|
||||
def header_constructor(rows, limit)
|
||||
for row in rows[1..limit-1]
|
||||
context, information = row.split(' ')
|
||||
|
|
@ -33,6 +42,9 @@ class Request
|
|||
end
|
||||
end
|
||||
|
||||
# Organizes the parameter information into a dict of parameters
|
||||
#
|
||||
# @param rows [Array] A list of the rows of parameters
|
||||
def param_constructor(rows)
|
||||
for row in rows[rows.find_index("")+1..rows.length]
|
||||
information = row.split(/&/)
|
||||
|
|
@ -43,6 +55,7 @@ class Request
|
|||
end
|
||||
end
|
||||
|
||||
# Organizes the resource information into a dict of resource parameters
|
||||
def resource_deconstructor
|
||||
information = @resource.split('?')[1].split(/&/)
|
||||
for info in information
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue