scorched 0.17 → 0.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGES.md +3 -0
- data/docs/02_fundamentals/04_requests_and_responses.md +1 -1
- data/lib/scorched/controller.rb +2 -2
- data/lib/scorched/version.rb +1 -1
- data/spec/controller_spec.rb +27 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cc448b9aca2411bb1687c2981fb9ba8d9f75429c
|
4
|
+
data.tar.gz: 66c20180446fd507f019c645d87cad07b2098f1c
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2f48eea992d507bd058115c412b37c3c7e86697fad098d9be60872d983307e868cf0fd55d0f74b0d564c6c7c6fa22f745fa715e1382cbd966b5a208fa1ce6421
|
7
|
+
data.tar.gz: 3cb2c849244e1a3316689d62575e524d5a2aa77aa77a7109bad7f836777187dfd544d30f475e562fb5bfc5018543dc2b1b1280ca3b06833d17e51dd668e8751c
|
data/CHANGES.md
CHANGED
@@ -1,6 +1,9 @@
|
|
1
1
|
Changelog
|
2
2
|
=========
|
3
3
|
|
4
|
+
### v0.18
|
5
|
+
* Redirects now use a 303 or 302 HTTP status code by default, depending on HTTP version (similar logic to Sinatra). Trailing slash redirects (triggered by :strip_trailing_slash) still uses a 307 status.
|
6
|
+
|
4
7
|
### v0.17
|
5
8
|
* Fixes an issue introduced in v0.16 where joining `SCRIPT_NAME` and `PATH_INFO` would sometimes produce a path with two forward slashes, and a related issue where `PATH_INFO` would sometimes be missing a leading forward slash when it should have had one.
|
6
9
|
* Mappings are now sorted by the best matching `media type` in addition to the existing logic that included definition order and priority. This required that mappings be sorted at request-time rather than at the time they're mapped. Note, because of limitations of `rack-accept`, this doesn't completely respect the HTTP spec when it comes to prioritising which media type to serve for a given request. Full support for the HTTP spec is intended for a future release.
|
@@ -34,4 +34,4 @@ If a target passes a request, the request is still considered _unmatched_ or _un
|
|
34
34
|
|
35
35
|
Redirections
|
36
36
|
------------
|
37
|
-
A common requirement of many applications is to redirect requests to another URL based on some kind of condition. Scorched offers the very simple `redirect` method which takes one required argument - the URL to redirect to - and an optional response status, which defaults to
|
37
|
+
A common requirement of many applications is to redirect requests to another URL based on some kind of condition. Scorched offers the very simple `redirect` method which takes one required argument - the absolute or relative URL to redirect to - and an optional response status, which defaults to either 303 or 302 depending on the HTTP protocol version used for the request.
|
data/lib/scorched/controller.rb
CHANGED
@@ -257,7 +257,7 @@ module Scorched
|
|
257
257
|
begin
|
258
258
|
catch(:halt) do
|
259
259
|
if config[:strip_trailing_slash] == :redirect && request.path =~ %r{./$}
|
260
|
-
redirect(request.path.chomp('/'))
|
260
|
+
redirect(request.path.chomp('/'), 307)
|
261
261
|
end
|
262
262
|
eligable_matches = matches.reject { |m| m.failed_condition }
|
263
263
|
pass if config[:auto_pass] && eligable_matches.empty?
|
@@ -344,7 +344,7 @@ module Scorched
|
|
344
344
|
invert ? !retval : !!retval
|
345
345
|
end
|
346
346
|
|
347
|
-
def redirect(url, status =
|
347
|
+
def redirect(url, status = (env['HTTP_VERSION'] == 'HTTP/1.1') ? 303 : 302)
|
348
348
|
response['Location'] = url
|
349
349
|
halt(status)
|
350
350
|
end
|
data/lib/scorched/version.rb
CHANGED
data/spec/controller_spec.rb
CHANGED
@@ -631,6 +631,33 @@ module Scorched
|
|
631
631
|
end
|
632
632
|
end
|
633
633
|
|
634
|
+
describe 'redirecting' do
|
635
|
+
it "redirects using 303 or 302 by default, depending on HTTP version" do
|
636
|
+
app.get('/cat') { redirect '/dog' }
|
637
|
+
response = rt.get('/cat', {}, 'HTTP_VERSION' => 'HTTP/1.1')
|
638
|
+
response.status.should == 303
|
639
|
+
response.location.should == '/dog'
|
640
|
+
response = rt.get('/cat', {}, 'HTTP_VERSION' => 'HTTP/1.0')
|
641
|
+
response.status.should == 302
|
642
|
+
response.location.should == '/dog'
|
643
|
+
end
|
644
|
+
|
645
|
+
it "allows the HTTP status to be overridden" do
|
646
|
+
app.get('/') { redirect '/somewhere', 308 }
|
647
|
+
rt.get('/').status.should == 308
|
648
|
+
end
|
649
|
+
|
650
|
+
it "halts the request after redirect" do
|
651
|
+
var = false
|
652
|
+
app.get('/') do
|
653
|
+
redirect '/somewhere'
|
654
|
+
var = true
|
655
|
+
end
|
656
|
+
rt.get('/')
|
657
|
+
var.should == false
|
658
|
+
end
|
659
|
+
end
|
660
|
+
|
634
661
|
describe "passing" do
|
635
662
|
it "invokes the next match" do
|
636
663
|
app.get('/') { response.body << 'hello'; pass }
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: scorched
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: '0.
|
4
|
+
version: '0.18'
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Tom Wardrop
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2013-
|
11
|
+
date: 2013-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rack
|