0
0
Fork 0

added Client to the request

This commit is contained in:
Gibheer 2012-11-15 06:43:40 +01:00
parent 721e1e61d9
commit 8f5486700b
2 changed files with 36 additions and 0 deletions

View File

@ -1,4 +1,5 @@
require_relative 'request/accept'
require_relative 'request/client'
require_relative 'request/parameter'
module Zero
@ -19,6 +20,10 @@ module Zero
@path ||= @env[CONST_PATH_INFO]
end
def client
@client ||= Request::Client.new(@env)
end
# get an object representing the parameters of the request
# @return [Parameter] object having all parameters
def params

View File

@ -0,0 +1,31 @@
module Zero
class Request
# This class represents all information about the client of a request.
class Client
# the key for the ip of the client
KEY_REMOTE_ADDR = 'REMOTE_ADDR'
# the key for the hostname
KEY_REMOTE_HOST = 'REMOTE_HOST'
# the key for the user agent
KEY_USER_AGENT = 'HTTP_USER_AGENT'
# creates a new client with the data of the request environment
# @param environment a hash representation of the request
def initialize(environment)
@address = environment[KEY_REMOTE_ADDR]
@hostname = environment[KEY_REMOTE_HOST]
@user_agent = environment[KEY_USER_AGENT]
end
# the ip address of the client
# @return [String] the address of the client
attr_reader :address
# the hostname of the client
# @return [String] the hostname of the client
attr_reader :hostname
# the user agent of the client
# @return [String] the user agent of the client
attr_reader :user_agent
end
end
end