0
0
Fork 0

added the implemention for #server

This commit is contained in:
Gibheer 2012-11-15 19:11:35 +01:00
parent 063cb77c1c
commit 022d29d633
2 changed files with 48 additions and 0 deletions

View File

@ -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

View File

@ -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