public
Description: Ruby on Rails
Homepage: http://rubyonrails.org
Clone URL: git://github.com/rails/rails.git
Added support for web servers that use PATH_INFO instead of REQUEST_URI 
like IIS #1014 [BradG/Nicholas Seckar]

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1211 
5ecf4fe2-1ee6-0310-87b1-e25e094e27de
dhh (author)
Mon Apr 18 08:43:07 -0700 2005
commit  3b9bf64130df2512d058d841341d9a082493141e
tree    4003e2fc24ca5ae11c41a29087665eef2eb1e4d6
parent  c1611a703c5366d7a85a5283ba1d721cfb5be43a
...
1
2
 
 
3
4
5
...
1
2
3
4
5
6
7
0
@@ -1,5 +1,7 @@
0
 *SVN*
0
 
0
+* Added support for web servers that use PATH_INFO instead of REQUEST_URI like IIS #1014 [BradG/Nicholas Seckar]
0
+
0
 * Added graceful handling of PUT, DELETE, and OPTIONS requests for a complete coverage of REST functionality #1136 [joshknowles@gmail.com]
0
 
0
 * Fixed that you can now pass an alternative :href option to link_to_function/remote in order to point to somewhere other than # if the javascript fails or is turned off. You can do the same with form_remote_tag by passing in :action. #1113 [Sam Stephenson]
...
48
49
50
51
 
 
 
 
 
52
53
54
...
48
49
50
 
51
52
53
54
55
56
57
58
0
@@ -48,7 +48,11 @@ module ActionController #:nodoc:
0
 
0
     def query_string
0
       return @cgi.query_string unless @cgi.query_string.nil? || @cgi.query_string.empty?
0
- parts = env['REQUEST_URI'].split('?')
0
+ unless env['REQUEST_URI'].nil?
0
+ parts = env['REQUEST_URI'].split('?')
0
+ else
0
+ return env['QUERY_STRING'] || ''
0
+ end
0
       parts.shift
0
       return parts.join('?')
0
     end
...
74
75
76
77
78
 
 
 
 
 
 
 
 
 
 
79
80
81
...
74
75
76
 
 
77
78
79
80
81
82
83
84
85
86
87
88
89
0
@@ -74,8 +74,16 @@ module ActionController
0
     end
0
     
0
     def request_uri
0
- (%r{^\w+\://[^/]+(/.*|$)$} =~ env['REQUEST_URI']) ? $1 : env['REQUEST_URI'] # Remove domain, which webrick puts into the request_uri.
0
- end
0
+ unless env['REQUEST_URI'].nil?
0
+ (%r{^\w+\://[^/]+(/.*|$)$} =~ env['REQUEST_URI']) ? $1 : env['REQUEST_URI'] # Remove domain, which webrick puts into the request_uri.
0
+ else # REQUEST_URI is blank under IIS - get this from PATH_INFO and SCRIPT_NAME
0
+ script_filename = env["SCRIPT_NAME"].to_s.match(%r{[^/]+$})
0
+ request_uri = env["PATH_INFO"]
0
+ request_uri.sub!(/#{script_filename}\//, '') unless script_filename.nil?
0
+ request_uri += '?' + env["QUERY_STRING"] unless env["QUERY_STRING"].nil? || env["QUERY_STRING"].empty?
0
+ return request_uri
0
+ end
0
+ end
0
 
0
     def protocol
0
       env["HTTPS"] == "on" ? 'https://' : 'http://'
...
83
84
85
86
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
87
88
89
...
83
84
85
 
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
0
@@ -83,7 +83,50 @@ class RequestTest < Test::Unit::TestCase
0
     @request.set_REQUEST_URI "/collaboration/hieraki/books/edit/2"
0
     @request.env['SCRIPT_NAME'] = "/collaboration/hieraki/dispatch.cgi"
0
     assert_equal "/collaboration/hieraki/books/edit/2", @request.request_uri
0
- assert_equal "/books/edit/2", @request.path
0
+ assert_equal "/books/edit/2", @request.path
0
+
0
+ # The following tests are for when REQUEST_URI is not supplied (as in IIS)
0
+ @request.set_REQUEST_URI nil
0
+ @request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1"
0
+ @request.env['SCRIPT_NAME'] = nil #"/path/dispatch.rb"
0
+ assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
0
+ assert_equal "/path/of/some/uri", @request.path
0
+
0
+ @request.env['PATH_INFO'] = "/path/of/some/uri?mapped=1"
0
+ @request.env['SCRIPT_NAME'] = "/path/dispatch.rb"
0
+ assert_equal "/path/of/some/uri?mapped=1", @request.request_uri
0
+ assert_equal "/of/some/uri", @request.path
0
+
0
+ @request.env['PATH_INFO'] = "/path/of/some/uri"
0
+ @request.env['SCRIPT_NAME'] = nil
0
+ assert_equal "/path/of/some/uri", @request.request_uri
0
+ assert_equal "/path/of/some/uri", @request.path
0
+
0
+ @request.env['PATH_INFO'] = "/"
0
+ assert_equal "/", @request.request_uri
0
+ assert_equal "/", @request.path
0
+
0
+ @request.env['PATH_INFO'] = "/?m=b"
0
+ assert_equal "/?m=b", @request.request_uri
0
+ assert_equal "/", @request.path
0
+
0
+ @request.env['PATH_INFO'] = "/"
0
+ @request.env['SCRIPT_NAME'] = "/dispatch.cgi"
0
+ assert_equal "/", @request.request_uri
0
+ assert_equal "/", @request.path
0
+
0
+ @request.env['PATH_INFO'] = "/hieraki/"
0
+ @request.env['SCRIPT_NAME'] = "/hieraki/dispatch.cgi"
0
+ assert_equal "/hieraki/", @request.request_uri
0
+ assert_equal "/", @request.path
0
+
0
+ # This test ensures that Rails uses REQUEST_URI over PATH_INFO
0
+ @request.env['REQUEST_URI'] = "/some/path"
0
+ @request.env['PATH_INFO'] = "/another/path"
0
+ @request.env['SCRIPT_NAME'] = "/dispatch.cgi"
0
+ assert_equal "/some/path", @request.request_uri
0
+ assert_equal "/some/path", @request.path
0
+
0
 
0
   end
0
   

Comments

    No one has commented yet.