ssl_routes 0.2.2 → 0.2.3

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 CHANGED
@@ -1,15 +1,15 @@
1
1
  ---
2
2
  !binary "U0hBMQ==":
3
3
  metadata.gz: !binary |-
4
- OWRjZTk0YmFmYjBlNmI4NmM5MGUwNzg5ODcyYmFkOTYxYzRlZTdiNA==
4
+ MjQ1MDVjODMyYjAwODJkMGU0ZmU0YjllNmYzZTRkMTVmYjg1ZGQzMw==
5
5
  data.tar.gz: !binary |-
6
- YjBkNTUwYWYxYWEyNzc0OThlYjNkNDM3YTg3ZWM4MDQ0NGM0MTEzNg==
6
+ ZTg1ZGE1NDU5ZDZmZDI3NzczNzJlOWIyZDRkZmE1MTM5NzBlYmViMA==
7
7
  !binary "U0hBNTEy":
8
8
  metadata.gz: !binary |-
9
- ODQwYWQyZTMyOGI1NTUwYmQ0MjEzNTJiMWY5ZDk2MWVmNGE2OTYxNzg2NTUw
10
- ZWQyNzk0NWQzNGFhOTg0ZjMwMjZmZWZmNjY0MWU1ODQ5M2M4NjQ4MWYwMjAz
11
- NTFkZGI1MGMzM2M1Zjc3MzBlZjRjMGNkOTc4MDRkYzljOGM0NmU=
9
+ NDZmZWU1MDU0YjM2MTFhZjgxMzViYzc2MGU1MjAyNjg3ZjBmOTAwNTllNTUy
10
+ OGQ0YjUxYWUzZjkzY2UwYmE2ZDc4MWEyYjc1ZmI0YWU2OTQ5YjI3MzU4M2Q0
11
+ ZTZlNWQyMWQ2YjgxMTkwYWQxOTcxOTU0OWM1OWNjMjAwM2QzZDQ=
12
12
  data.tar.gz: !binary |-
13
- ZGQ1M2Q2MzBiNTkwNDdhNTJhYThhMDFhM2FmOWFmZWYxMTZlZjYzYTQ2NWRl
14
- YTM5MDU2MzA0MGU4NDM2ZGZlNDQ5MzQzNWFjNmVjNzhlYWM2ODcwNjVkNTBh
15
- MDgwMjFmZWMyM2MxMGNlNjNlNDg2MGYxMmM4YTRjMTVkMWNmZmY=
13
+ ODc5MTRhZTk1MzZkMjM1NDE2Yzg0MGI5ODY2MTkwYTNkMGJkYzE1MDFiYzU4
14
+ ODEyY2MzN2NhOTBmZmNmYzA5YzQ4MjMyMjQ0MDg5NmZjYTdhNWVkNjJlMGVi
15
+ MzRmOGI3ODk2ZjdlYjljZDYyODQzYmJhOWM2MzJlYmVkYmM2OTI=
@@ -25,9 +25,8 @@ module SslRoutes
25
25
  when String then options[self.parameter]
26
26
  when TrueClass then 'https'
27
27
  when FalseClass then 'http'
28
- else 'http' # maybe this should be current
28
+ else current
29
29
  end
30
- target = current if [:all, :both].include? options[self.parameter]
31
30
  target = 'https' if self.secure_session && current_user
32
31
  target = options[:protocol] if options[:protocol]
33
32
  [ current, target.split(':').first ]
@@ -36,8 +35,8 @@ module SslRoutes
36
35
  private
37
36
 
38
37
  def ensure_protocol
39
- routes = Rails.application.routes
40
- options = routes.recognize_path request.path, {:method => request.env['REQUEST_METHOD']}
38
+ router = Rails.application.routes.router
39
+ options = recognize_request(router, self.request)
41
40
  current, target = determine_protocols(options)
42
41
  if (current != target && !request.xhr? && request.get?)
43
42
  flash.keep
@@ -48,6 +47,31 @@ module SslRoutes
48
47
  end
49
48
  end
50
49
 
50
+ Constraints = ::ActionDispatch::Routing::Mapper::Constraints
51
+ Dispatcher = ::ActionDispatch::Routing::RouteSet::Dispatcher
52
+
53
+ def recognize_request(router, req)
54
+ router.recognize(req) do |route, matches, params|
55
+ params.each do |key, value|
56
+ if value.is_a?(String)
57
+ value = value.dup.force_encoding(Encoding::BINARY) if value.encoding_aware?
58
+ params[key] = URI.parser.unescape(value)
59
+ end
60
+ end
61
+
62
+ dispatcher = route.app
63
+ while dispatcher.is_a?(Constraints) && dispatcher.matches?(env) do
64
+ dispatcher = dispatcher.app
65
+ end
66
+
67
+ if dispatcher.is_a?(Dispatcher) && dispatcher.controller(params, false)
68
+ dispatcher.prepare_params!(params)
69
+ return params
70
+ end
71
+ end
72
+
73
+ raise ActionController::RoutingError, "No route matches #{path.inspect}"
74
+ end
51
75
  end
52
76
 
53
77
  module ActionDispatch
@@ -60,12 +84,9 @@ module SslRoutes
60
84
  ac = self.respond_to?(:controller) ? self.controller : self
61
85
  if ac.respond_to?(:enable_ssl) && ac.enable_ssl
62
86
  if options.is_a?(Hash)
63
- case options
64
- when Hash
65
- current, target = ac.determine_protocols(options)
66
- if current != target
67
- options.merge!({ :protocol => target, :only_path => false })
68
- end
87
+ current, target = ac.determine_protocols(options)
88
+ if current != target
89
+ options.merge!({ :protocol => target, :only_path => false })
69
90
  end
70
91
  end
71
92
  end
@@ -1,5 +1,5 @@
1
1
  module SslRoutes
2
2
 
3
- VERSION = '0.2.2'
3
+ VERSION = '0.2.3'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ssl_routes
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.2
4
+ version: 0.2.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Cedric Howe
@@ -10,7 +10,7 @@ authors:
10
10
  autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
- date: 2013-10-04 00:00:00.000000000 Z
13
+ date: 2014-01-24 00:00:00.000000000 Z
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
16
16
  name: rails