Class: Weary::Env

Inherits:
Object
  • Object
show all
Defined in:
lib/weary/env.rb

Instance Method Summary (collapse)

Constructor Details

- (Env) initialize(request)



3
4
5
# File 'lib/weary/env.rb', line 3

def initialize(request)
  @request = request
end

Instance Method Details

- (Object) env



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/weary/env.rb', line 11

def env
  {
    'REQUEST_METHOD'  => @request.method,
    'SCRIPT_NAME'     => "",
    'PATH_INFO'       => @request.uri.path,
    'QUERY_STRING'    => @request.uri.query || "",
    'SERVER_NAME'     => @request.uri.host,
    'SERVER_PORT'     => port,
    'REQUEST_URI'     => @request.uri.request_uri,
    'HTTP_HOST'       => http_host,
    'rack.url_scheme' => @request.uri.scheme,
    'rack.input'      => @request.body,
    'weary.request'   => @request
  }.update headers
end

- (Object) headers



7
8
9
# File 'lib/weary/env.rb', line 7

def headers
  Hash[@request.headers.map {|k,v| ["HTTP_#{k.to_s.upcase.gsub('-','_')}", v] }]
end

- (Object) http_host



31
32
33
34
# File 'lib/weary/env.rb', line 31

def http_host
  uri = @request.uri
  uri.host + (uri.normalized_port ? ":#{uri.normalized_port}" : "")
end

- (Object) port



27
28
29
# File 'lib/weary/env.rb', line 27

def port
  (@request.uri.port || @request.uri.inferred_port).to_s
end