diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/zero/request.rb | 5 | ||||
-rw-r--r-- | lib/zero/request/client.rb | 31 |
2 files changed, 36 insertions, 0 deletions
diff --git a/lib/zero/request.rb b/lib/zero/request.rb index 30e891e..f3d40d6 100644 --- a/lib/zero/request.rb +++ b/lib/zero/request.rb @@ -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 diff --git a/lib/zero/request/client.rb b/lib/zero/request/client.rb new file mode 100644 index 0000000..2a27cb7 --- /dev/null +++ b/lib/zero/request/client.rb @@ -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 |