Class: RSence::Request

Inherits:
Rack::Request
  • Object
show all
Defined in:
lib/rsence/http/request.rb

Overview

Simple Request class, slightly more involved than the Rack::Request it’s extending.

Defined Under Namespace

Classes: RequestHeader

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Request

Returns a new instance of Request.



21
22
23
24
25
26
27
# File 'lib/rsence/http/request.rb', line 21

def initialize(env)
  @header = RequestHeader.new
  super
  env2header()
  @path = path_info()
  @query = params()
end

Instance Attribute Details

#headerObject (readonly)

Returns the value of attribute header.



15
16
17
# File 'lib/rsence/http/request.rb', line 15

def header
  @header
end

#pathObject (readonly)

Returns the value of attribute path.



15
16
17
# File 'lib/rsence/http/request.rb', line 15

def path
  @path
end

#queryObject (readonly)

Returns the value of attribute query.



15
16
17
# File 'lib/rsence/http/request.rb', line 15

def query
  @query
end

Instance Method Details

#env2headerObject



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
# File 'lib/rsence/http/request.rb', line 31

def env2header
  [ ['SERVER_NAME',           'server-name'],
    ['HTTP_USER_AGENT',       'user-agent'],
    ['HTTP_ACCEPT_ENCODING',  'accept-encoding'],
    ['PATH_INFO',             'path-info'],
    ['HTTP_HOST',             'host'],
    ['HTTP_ACCEPT_LANGUAGE',  'accept-language'],
    ['SERVER_PROTOCOL',       'server-protocol'],
    ['REQUEST_PATH',          'request-path'],
    ['HTTP_KEEP_ALIVE',       'keep-alive'],
    ['SERVER_SOFTWARE',       'server-software'],
    ['REMOTE_ADDR',           'remote-addr'],
    ['HTTP_REFERER',          'referer'],
    ['HTTP_VERSION',          'version'],
    ['HTTP_ACCEPT_CHARSET',   'accept-charset'],
    ['REQUEST_URI',           'request-uri'],
    ['SERVER_PORT',           'server-port'],
    ['QUERY_STRING',          'query-string'],
    ['HTTP_ACCEPT',           'accept'],
    ['REQUEST_METHOD',        'request-method'],
    ['HTTP_CONNECTION',       'connection'],
    ['HTTP_SOAPACTION',       'soapaction'],
    ['HTTP_FORWARDED_HOST',   'forwarded-host']
  ].each do |env_key,header_key|
    if @env.has_key?(env_key)
      @header[header_key] = @env[env_key]
    end
    if env_key.start_with?( 'HTTP_' )
      x_env_key = "HTTP_X#{env_key[4..-1]}"
      if @env.has_key?( x_env_key )
        @header["x-#{header_key}"] = @env[ x_env_key ]
      end
    end
  end
end

#unparsed_uriObject



28
29
30
# File 'lib/rsence/http/request.rb', line 28

def unparsed_uri
  return @header['request-uri']
end