|
19 | 19 | expect(request.env["rack.url_scheme"]).to eq('http') |
20 | 20 | expect(request.env['FRAGMENT'].to_s).to be_empty |
21 | 21 | expect(request.env['QUERY_STRING'].to_s).to be_empty |
22 | | - |
| 22 | + |
23 | 23 | expect(request).to validate_with_lint |
24 | 24 | end |
25 | | - |
| 25 | + |
26 | 26 | it 'should upcase headers' do |
27 | 27 | request = R("GET / HTTP/1.1\r\nX-Invisible: yo\r\n\r\n") |
28 | 28 | expect(request.env['HTTP_X_INVISIBLE']).to eq('yo') |
29 | 29 | end |
30 | | - |
| 30 | + |
31 | 31 | it 'should not prepend HTTP_ to Content-Type and Content-Length' do |
32 | 32 | request = R("POST / HTTP/1.1\r\nHost: localhost\r\nContent-Type: text/html\r\nContent-Length: 2\r\n\r\naa") |
33 | 33 | expect(request.env.keys).not_to include('HTTP_CONTENT_TYPE', 'HTTP_CONTENT_LENGTH') |
34 | 34 | expect(request.env.keys).to include('CONTENT_TYPE', 'CONTENT_LENGTH') |
35 | | - |
| 35 | + |
36 | 36 | expect(request).to validate_with_lint |
37 | 37 | end |
38 | | - |
| 38 | + |
39 | 39 | it 'should raise error on invalid request line' do |
40 | 40 | expect { R("GET / SsUTF/1.1") }.to raise_error(InvalidRequest) |
41 | 41 | expect { R("GET / HTTP/1.1yousmelllikecheeze") }.to raise_error(InvalidRequest) |
42 | 42 | end |
43 | | - |
| 43 | + |
44 | 44 | it 'should support fragment in uri' do |
45 | 45 | request = R("GET /forums/1/topics/2375?page=1#posts-17408 HTTP/1.1\r\nHost: localhost\r\n\r\n") |
46 | 46 |
|
47 | 47 | expect(request.env['REQUEST_URI']).to eq('/forums/1/topics/2375?page=1') |
48 | 48 | expect(request.env['PATH_INFO']).to eq('/forums/1/topics/2375') |
49 | 49 | expect(request.env['QUERY_STRING']).to eq('page=1') |
50 | 50 | expect(request.env['FRAGMENT']).to eq('posts-17408') |
51 | | - |
| 51 | + |
52 | 52 | expect(request).to validate_with_lint |
53 | 53 | end |
54 | | - |
| 54 | + |
55 | 55 | it 'should parse path with query string' do |
56 | 56 | request = R("GET /index.html?234235 HTTP/1.1\r\nHost: localhost\r\n\r\n") |
57 | 57 | expect(request.env['REQUEST_PATH']).to eq('/index.html') |
58 | 58 | expect(request.env['QUERY_STRING']).to eq('234235') |
59 | 59 | expect(request.env['FRAGMENT']).to be_nil |
60 | | - |
| 60 | + |
61 | 61 | expect(request).to validate_with_lint |
62 | 62 | end |
63 | | - |
| 63 | + |
64 | 64 | it 'should parse headers from GET request' do |
65 | 65 | request = R(<<-EOS, true) |
66 | 66 | GET / HTTP/1.1 |
|
151 | 151 |
|
152 | 152 | expect(request).to validate_with_lint |
153 | 153 | end |
154 | | - |
| 154 | + |
155 | 155 | it 'should parse even with stupid Content-Length' do |
156 | 156 | body = <<-EOS.chomp |
157 | 157 | POST / HTTP/1.1 |
|
165 | 165 | request.body.rewind |
166 | 166 | expect(request.body.read).to eq('aye') |
167 | 167 | end |
168 | | - |
| 168 | + |
169 | 169 | it "should parse ie6 urls" do |
170 | 170 | %w(/some/random/path" |
171 | 171 | /some/random/path> |
|
184 | 184 | expect(parser).not_to be_error |
185 | 185 | end |
186 | 186 | end |
187 | | - |
| 187 | + |
188 | 188 | it "should parse absolute request URI" do |
189 | 189 | request = R(<<-EOS, true) |
190 | 190 | GET http://localhost:3000/hi?qs#f HTTP/1.1 |
191 | 191 | Host: localhost:3000 |
192 | 192 |
|
193 | 193 | EOS |
194 | | - |
| 194 | + |
195 | 195 | expect(request.env['PATH_INFO']).to eq('/hi') |
196 | 196 | expect(request.env['REQUEST_PATH']).to eq('/hi') |
197 | 197 | expect(request.env['REQUEST_URI']).to eq('/hi?qs') |
|
236 | 236 | expect(req).to have_key('HTTP_HOS_T') |
237 | 237 | } |
238 | 238 | end |
239 | | - |
| 239 | + |
240 | 240 | it "should parse PATH_INFO with semicolon" do |
241 | 241 | qs = "QUERY_STRING" |
242 | 242 | pi = "PATH_INFO" |
|
257 | 257 | expect(env["REQUEST_URI"]).to eq(uri) |
258 | 258 |
|
259 | 259 | next if uri == "*" |
260 | | - |
| 260 | + |
261 | 261 | # Validate w/ Ruby's URI.parse |
262 | 262 | uri = URI.parse("http://example.com#{uri}") |
263 | 263 | expect(env[qs]).to eq(uri.query.to_s) |
264 | 264 | expect(env[pi]).to eq(uri.path) |
265 | 265 | end |
266 | 266 | end |
267 | | - |
| 267 | + |
268 | 268 | it "should parse IE7 badly encoded URL" do |
269 | 269 | body = <<-EOS.chomp |
270 | 270 | GET /H%uFFFDhnchenbrustfilet HTTP/1.1 |
|
275 | 275 |
|
276 | 276 | expect(request.env['REQUEST_URI']).to eq("/H%uFFFDhnchenbrustfilet") |
277 | 277 | end |
| 278 | + |
| 279 | + describe "with Rack < 3", unless: ::Rack.release >= "3" do |
| 280 | + it "should add required env" do |
| 281 | + request = R("GET / HTTP/1.1\r\nHost: localhost\r\n\r\n") |
| 282 | + expect(request.env).to include("rack.version", "rack.multithread", "rack.multiprocess", "rack.run_once") |
| 283 | + end |
| 284 | + end |
| 285 | + |
| 286 | + describe "with Rack >= 3", if: ::Rack.release >= "3" do |
| 287 | + it "should not add not required env" do |
| 288 | + request = R("GET / HTTP/1.1\r\nHost: localhost\r\n\r\n") |
| 289 | + expect(request.env).not_to include("rack.version", "rack.multithread", "rack.multiprocess", "rack.run_once") |
| 290 | + end |
| 291 | + end |
278 | 292 | end |
0 commit comments