Permalink
Newer
Older
100644 40 lines (32 sloc) 1.03 KB
1
require 'rack/utils'
2
Feb 16, 2007
3
module Rack
4
class Request
5
def initialize(env)
6
@env = env
7
end
8
9
def body; @env["rack.input"] end
10
def scheme; @env["rack.url_scheme"] end
11
def method; @env["REQUEST_METHOD"] end
12
def script_name; @env["SCRIPT_NAME"].to_s end
13
def path_info; @env["PATH_INFO"].to_s end
14
def host; @env["HTTP_HOST"] || @env["SERVER_NAME"] end
15
def path_info; @env["PATH_INFO"].to_s end
16
def port; @env["SERVER_PORT"].to_i end
17
18
def GET
19
Utils.parse_query(@env["QUERY_STRING"])
Feb 16, 2007
20
end
21
22
def POST
23
@env["rack.request.formvars"] ||= body.read
24
Utils.parse_query(@env["rack.request.formvars"])
Feb 16, 2007
25
end
26
27
def params
28
self.GET.update(self.POST)
29
end
30
31
def cookies
32
Utils.parse_query(@env["HTTP_COOKIE"], ';,') # XXX sure?
Feb 16, 2007
33
end
34
35
def xhr?
36
@env["HTTP_X_REQUESTED_WITH"] == "XMLHttpRequest"
37
end
38
end
39
end