padrino-core 0.18.5 → 0.18.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/padrino-core/application/routing.rb +11 -1
- data/lib/padrino-core/path_router/route.rb +1 -1
- data/lib/padrino-core/version.rb +1 -1
- data/test/test_routing.rb +65 -0
- metadata +4 -4
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 37ece5f8ac3fea18d83aa9c9dcd392b3c3c584bd314197cc4a1afe41b1ce4ea6
|
|
4
|
+
data.tar.gz: 693070c79a2bdd601a59977d14388254ad845795653a6c4a1fa1327bd6d7a10a
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: '01139ddfbe043ec2e177f4bdd9fa44ba010df56f467ddf7a56b187a60de8b2978c8df271807232b220054d32af7963ffa2a1d573bfb5078f7e454b43911071d8'
|
|
7
|
+
data.tar.gz: bd34c2503675242fd859c47e6e73421b97b404ae1617aa1dca5d25a64ca1ea10d377b6de29b444ef94c8fd823e8c27b3cd7d9eb23de1a546943ff0c5ce53d35f
|
|
@@ -626,6 +626,7 @@ module Padrino
|
|
|
626
626
|
# get :list, provides: [:js, :json] # => "/list.{!format,js|json}"
|
|
627
627
|
# get :list, provides: [:html, :js, :json] # => "/list(.{!format,js|json})"
|
|
628
628
|
# get :list, priority: :low # Defers route to be last
|
|
629
|
+
# get :index, host: 'admin.example.com' # Only for that host (a String, Regexp or Array)
|
|
629
630
|
# get /pattern/, name: :foo, generate_with: '/foo' # Generates :foo as /foo
|
|
630
631
|
def route(verb, path, *args, &block)
|
|
631
632
|
options =
|
|
@@ -1121,7 +1122,10 @@ module Padrino
|
|
|
1121
1122
|
first_time = true
|
|
1122
1123
|
|
|
1123
1124
|
routes = base.compiled_router.call(@request) do |route, params|
|
|
1124
|
-
|
|
1125
|
+
# ceiling: a route skipped here for its host or agent still counts for the 405 check below;
|
|
1126
|
+
# drop those routes from +routes+ before the check to answer 404 instead.
|
|
1127
|
+
next if route.host && !host_matches?(route.host)
|
|
1128
|
+
next if route.user_agent && !(route.user_agent === @request.user_agent)
|
|
1125
1129
|
original_params, parent_layout = @params.dup, @layout
|
|
1126
1130
|
returned_pass_block = invoke_route(route, params, first_time)
|
|
1127
1131
|
pass_block = returned_pass_block if returned_pass_block
|
|
@@ -1182,6 +1186,12 @@ module Padrino
|
|
|
1182
1186
|
end
|
|
1183
1187
|
end
|
|
1184
1188
|
|
|
1189
|
+
# A route's +host:+ is a String (compared ignoring case), a Regexp or an Array of them.
|
|
1190
|
+
def host_matches?(hosts)
|
|
1191
|
+
host = @request.host.to_s
|
|
1192
|
+
Array(hosts).any? { |pattern| pattern.is_a?(String) ? pattern.casecmp?(host) : pattern === host }
|
|
1193
|
+
end
|
|
1194
|
+
|
|
1185
1195
|
def captures_from_params(params)
|
|
1186
1196
|
if params[:captures].instance_of?(Array) && !params[:captures].empty?
|
|
1187
1197
|
params.delete(:captures)
|
|
@@ -38,7 +38,7 @@ module Padrino
|
|
|
38
38
|
# The accessors will be used in other classes
|
|
39
39
|
#
|
|
40
40
|
attr_accessor :action, :cache, :cache_key, :cache_expires,
|
|
41
|
-
:parent, :use_layout, :controller, :user_agent, :path_for_generation, :default_values,
|
|
41
|
+
:parent, :use_layout, :controller, :host, :user_agent, :path_for_generation, :default_values,
|
|
42
42
|
:provided_formats
|
|
43
43
|
|
|
44
44
|
##
|
data/lib/padrino-core/version.rb
CHANGED
data/test/test_routing.rb
CHANGED
|
@@ -563,6 +563,71 @@ describe 'Routing' do
|
|
|
563
563
|
assert_equal 'hello IE', body
|
|
564
564
|
end
|
|
565
565
|
|
|
566
|
+
it 'should match a user agent given as a String exactly' do
|
|
567
|
+
mock_app do
|
|
568
|
+
get('/main', agent: 'Exact Agent') { 'exact' }
|
|
569
|
+
get('/main') { 'hello' }
|
|
570
|
+
end
|
|
571
|
+
get '/main', {}, { 'HTTP_USER_AGENT' => 'Exact Agent' }
|
|
572
|
+
assert_equal 'exact', body
|
|
573
|
+
get '/main', {}, { 'HTTP_USER_AGENT' => 'Exact Agent 2' }
|
|
574
|
+
assert_equal 'hello', body
|
|
575
|
+
get '/main'
|
|
576
|
+
assert_equal 'hello', body
|
|
577
|
+
end
|
|
578
|
+
|
|
579
|
+
it 'should match hosts' do
|
|
580
|
+
mock_app do
|
|
581
|
+
get(:index, host: 'admin.example.com') { 'admin' }
|
|
582
|
+
get(:index) { 'public' }
|
|
583
|
+
get('/api', host: /\Aapi\./) { 'api' }
|
|
584
|
+
end
|
|
585
|
+
get '/', {}, 'HTTP_HOST' => 'admin.example.com'
|
|
586
|
+
assert_equal 'admin', body
|
|
587
|
+
get '/', {}, 'HTTP_HOST' => 'admin.example.com:3000'
|
|
588
|
+
assert_equal 'admin', body
|
|
589
|
+
get '/', {}, 'HTTP_HOST' => 'www.example.com'
|
|
590
|
+
assert_equal 'public', body
|
|
591
|
+
get '/', {}, 'HTTP_HOST' => 'sub.admin.example.com'
|
|
592
|
+
assert_equal 'public', body
|
|
593
|
+
get '/api', {}, 'HTTP_HOST' => 'api.example.com'
|
|
594
|
+
assert_equal 'api', body
|
|
595
|
+
get '/api', {}, 'HTTP_HOST' => 'www.example.com'
|
|
596
|
+
assert_equal 404, status
|
|
597
|
+
end
|
|
598
|
+
|
|
599
|
+
it 'should match a host given in any case, or one of an Array of hosts' do
|
|
600
|
+
mock_app do
|
|
601
|
+
get(:index, host: 'admin.example.com') { 'admin' }
|
|
602
|
+
get('/api', host: ['api.example.com', /\Aapi\d\./]) { 'api' }
|
|
603
|
+
get(:index) { 'public' }
|
|
604
|
+
end
|
|
605
|
+
get '/', {}, 'HTTP_HOST' => 'Admin.Example.COM'
|
|
606
|
+
assert_equal 'admin', body
|
|
607
|
+
get '/api', {}, 'HTTP_HOST' => 'api.example.com'
|
|
608
|
+
assert_equal 'api', body
|
|
609
|
+
get '/api', {}, 'HTTP_HOST' => 'api2.example.com'
|
|
610
|
+
assert_equal 'api', body
|
|
611
|
+
get '/api', {}, 'HTTP_HOST' => 'www.example.com'
|
|
612
|
+
assert_equal 404, status
|
|
613
|
+
end
|
|
614
|
+
|
|
615
|
+
it 'should match hosts given to a controller, without running its filters for other hosts' do
|
|
616
|
+
mock_app do
|
|
617
|
+
controller :admin, map: '/', conditions: { host: 'admin.example.com' } do
|
|
618
|
+
before { response['x-admin'] = 'ran' }
|
|
619
|
+
get(:index) { 'admin' }
|
|
620
|
+
end
|
|
621
|
+
get(:index) { 'public' }
|
|
622
|
+
end
|
|
623
|
+
get '/', {}, 'HTTP_HOST' => 'admin.example.com'
|
|
624
|
+
assert_equal 'admin', body
|
|
625
|
+
assert_equal 'ran', response['x-admin']
|
|
626
|
+
get '/', {}, 'HTTP_HOST' => 'www.example.com'
|
|
627
|
+
assert_equal 'public', body
|
|
628
|
+
assert_nil response['x-admin']
|
|
629
|
+
end
|
|
630
|
+
|
|
566
631
|
it 'should use regex for parts of a route' do
|
|
567
632
|
mock_app do
|
|
568
633
|
get('/main/:id', id: /\d+/) { "hello #{params[:id]}" }
|
metadata
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: padrino-core
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.18.
|
|
4
|
+
version: 0.18.6
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Padrino Team
|
|
@@ -11,7 +11,7 @@ authors:
|
|
|
11
11
|
autorequire:
|
|
12
12
|
bindir: bin
|
|
13
13
|
cert_chain: []
|
|
14
|
-
date: 2026-11-
|
|
14
|
+
date: 2026-11-24 00:00:00.000000000 Z
|
|
15
15
|
dependencies:
|
|
16
16
|
- !ruby/object:Gem::Dependency
|
|
17
17
|
name: ostruct
|
|
@@ -33,14 +33,14 @@ dependencies:
|
|
|
33
33
|
requirements:
|
|
34
34
|
- - '='
|
|
35
35
|
- !ruby/object:Gem::Version
|
|
36
|
-
version: 0.18.
|
|
36
|
+
version: 0.18.6
|
|
37
37
|
type: :runtime
|
|
38
38
|
prerelease: false
|
|
39
39
|
version_requirements: !ruby/object:Gem::Requirement
|
|
40
40
|
requirements:
|
|
41
41
|
- - '='
|
|
42
42
|
- !ruby/object:Gem::Version
|
|
43
|
-
version: 0.18.
|
|
43
|
+
version: 0.18.6
|
|
44
44
|
- !ruby/object:Gem::Dependency
|
|
45
45
|
name: rackup
|
|
46
46
|
requirement: !ruby/object:Gem::Requirement
|