diff options
author | Gibheer <gibheer@gmail.com> | 2012-11-15 19:11:35 +0100 |
---|---|---|
committer | Gibheer <gibheer@gmail.com> | 2012-11-15 19:11:35 +0100 |
commit | 022d29d633a6acd25a048f4dd77c09bf347385fb (patch) | |
tree | ee7a0e4e0f98fb1863f358008e3db8381e17b5fe | |
parent | 063cb77c1cc95e057089fafdda75d6b1bbd2fef5 (diff) |
added the implemention for #server
-rw-r--r-- | lib/zero/request.rb | 7 | ||||
-rw-r--r-- | lib/zero/request/server.rb | 41 |
2 files changed, 48 insertions, 0 deletions
diff --git a/lib/zero/request.rb b/lib/zero/request.rb index 32379e3..22c5a52 100644 --- a/lib/zero/request.rb +++ b/lib/zero/request.rb @@ -1,6 +1,7 @@ require_relative 'request/accept' require_relative 'request/client' require_relative 'request/parameter' +require_relative 'request/server' module Zero # This class wraps around a rack environment for easier access to all data. @@ -26,6 +27,12 @@ module Zero @client ||= Request::Client.new(@env) end + # get the information on the server + # @return [Server] information on the running server + def server + @server ||= Request::Server.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/server.rb b/lib/zero/request/server.rb new file mode 100644 index 0000000..0aa82c8 --- /dev/null +++ b/lib/zero/request/server.rb @@ -0,0 +1,41 @@ +module Zero + class Request + # This class represents all server related information of a request. + class Server + # the key for the server name + # @api private + KEY_SERVER_NAME = 'SERVER_NAME' + # the key for the server port + # @api private + KEY_SERVER_PORT = 'SERVER_PORT' + # the key for the server protocol + # @api private + KEY_SERVER_PROTOCOL = 'SERVER_PROTOCOL' + # the key for the server software + # @api private + KEY_SERVER_SOFTWARE = 'SERVER_SOFTWARE' + + # This creates a new server instance extracting all server related + # information from the environment. + def initialize(environment) + @hostname = environment[KEY_SERVER_NAME] + @port = environment[KEY_SERVER_PORT].to_i + @protocol = environment[KEY_SERVER_PROTOCOL] + @software = environment[KEY_SERVER_SOFTWARE] + end + + # get the port + # @return [Numeric] the port + attr_reader :port + # get the hostname of the server + # @return [String] the hostname + attr_reader :hostname + # get the protocol of the server (normally it should be HTTP/1.1) + # @return [String] the protocol + attr_reader :protocol + # get the server software + # @return [String] the server software name + attr_reader :software + end + end +end |