sinatra-cors 0.2.0 → 1.0.0

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.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/sinatra/cors.rb +18 -10
  3. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: ff5b1f839cff23f60932ac3e449d8f429550dcae
4
- data.tar.gz: 618991731d2f808e37b028bb884fc59a275e02d5
3
+ metadata.gz: '08732720be636ff166b5b624f0c508a8a4942c9d'
4
+ data.tar.gz: 9cf55a3b5b7b56791fca4be7b982fdd41fbab292
5
5
  SHA512:
6
- metadata.gz: 5a7f3ae81a92f2beb2b1b8c28bdfdd9d787b9fbb4c86030e4cbec0bdc9d89d06e7d0aeef1749606717a566cb3d75195b02060f2d5995c273d6635667daf880a6
7
- data.tar.gz: 5aa1f60d221502d4922e54cd08f24d43be12cd62236407e55ec1a678cb7feac3967eeb799e695e83a7bb00f0f9d3e674618c4f805597cfc9c2580f1ae733cd2b
6
+ metadata.gz: 7bf3c8b5814c85f1b3e6cb837beb84eb9686070ed353dfab42c727dc27e6e366a0e2657e2c3acba84e80d2d18de073f4e7c1ea9b0099b26d5be4983151c3abc1
7
+ data.tar.gz: 0f870fabdec2bcbbdcac5e6ff1509331beee2670d18edeab59a2323c52873a23d7dcc7567cce92293874e33f6a939b3d71038cbb8db1bdf6266e18eafc2a30bd
@@ -57,6 +57,19 @@ module Sinatra
57
57
  settings.allow_origin == "*" || settings.allow_origin.split.include?(request.env["HTTP_ORIGIN"])
58
58
  end
59
59
 
60
+ def allowed_methods
61
+ matches = []
62
+ settings.routes.each do |method, routes|
63
+ routes.each do |route|
64
+ process_route(route[0], route[1]) do |application, pattern|
65
+ matches << method
66
+ end
67
+ end
68
+ end
69
+
70
+ matches
71
+ end
72
+
60
73
  private
61
74
 
62
75
  def bad_method_message
@@ -93,18 +106,11 @@ to requests with these headers, you can add them to the `allow_headers` sinatra
93
106
  end
94
107
 
95
108
  app.options "*", is_cors_preflight: true do
96
- matches = []
97
- settings.routes.each do |method, routes|
98
- routes.each do |route|
99
- process_route(route[0], route[1], route[2]) do |application, pattern|
100
- matches << method
101
- end
102
- end
103
- end
109
+ allow = allowed_methods
104
110
 
105
- pass if matches.size == 1
111
+ pass if allow.size == 1
106
112
 
107
- response.headers["Allow"] = matches.join " "
113
+ response.headers["Allow"] = allow.join " "
108
114
  end
109
115
 
110
116
  app.after do
@@ -112,4 +118,6 @@ to requests with these headers, you can add them to the `allow_headers` sinatra
112
118
  end
113
119
  end
114
120
  end
121
+
122
+ register Cors
115
123
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: sinatra-cors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.0
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jason Desrosiers
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-06-28 00:00:00.000000000 Z
11
+ date: 2017-07-25 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: 'This Sinatra plugin supports the full CORS spec including automatic
14
14
  support for CORS preflight (OPTIONS) requests. It uses CORS security best practices. The