sinatra-cors 0.1.1 → 0.2.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.
- checksums.yaml +4 -4
- data/lib/sinatra/cors.rb +23 -12
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ff5b1f839cff23f60932ac3e449d8f429550dcae
|
4
|
+
data.tar.gz: 618991731d2f808e37b028bb884fc59a275e02d5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 5a7f3ae81a92f2beb2b1b8c28bdfdd9d787b9fbb4c86030e4cbec0bdc9d89d06e7d0aeef1749606717a566cb3d75195b02060f2d5995c273d6635667daf880a6
|
7
|
+
data.tar.gz: 5aa1f60d221502d4922e54cd08f24d43be12cd62236407e55ec1a678cb7feac3967eeb799e695e83a7bb00f0f9d3e674618c4f805597cfc9c2580f1ae733cd2b
|
data/lib/sinatra/cors.rb
CHANGED
@@ -10,6 +10,7 @@ module Sinatra
|
|
10
10
|
logger.warn bad_method_message
|
11
11
|
return
|
12
12
|
end
|
13
|
+
|
13
14
|
unless headers_are_allowed?
|
14
15
|
logger.warn bad_headers_message
|
15
16
|
return
|
@@ -41,16 +42,15 @@ module Sinatra
|
|
41
42
|
end
|
42
43
|
|
43
44
|
def method_is_allowed?
|
44
|
-
allow_methods = settings.allow_methods
|
45
|
-
request_method = request.env["HTTP_ACCESS_CONTROL_REQUEST_METHOD"]
|
46
|
-
allow_methods.
|
45
|
+
allow_methods = settings.allow_methods.split & response.headers["Allow"].split
|
46
|
+
request_method = request.env["HTTP_ACCESS_CONTROL_REQUEST_METHOD"]
|
47
|
+
allow_methods.include? request_method
|
47
48
|
end
|
48
49
|
|
49
50
|
def headers_are_allowed?
|
50
|
-
allow_headers = settings.allow_headers
|
51
|
+
allow_headers = settings.allow_headers
|
51
52
|
request_headers = request.env["HTTP_ACCESS_CONTROL_REQUEST_HEADERS"] || ""
|
52
|
-
|
53
|
-
diff.size == 0
|
53
|
+
(request_headers.split - allow_headers.split).empty?
|
54
54
|
end
|
55
55
|
|
56
56
|
def origin_is_allowed?
|
@@ -81,19 +81,30 @@ to requests with these headers, you can add them to the `allow_headers` sinatra
|
|
81
81
|
def self.registered(app)
|
82
82
|
app.helpers Cors::Helpers
|
83
83
|
|
84
|
-
app.
|
85
|
-
app.
|
86
|
-
app.
|
84
|
+
app.set :allow_origin, ""
|
85
|
+
app.set :allow_methods, ""
|
86
|
+
app.set :allow_headers, ""
|
87
87
|
app.disable :max_age
|
88
88
|
app.disable :expose_headers
|
89
89
|
app.disable :allow_credentials
|
90
90
|
|
91
|
-
app.set(:is_cors_preflight)
|
91
|
+
app.set(:is_cors_preflight) do |bool|
|
92
92
|
condition { is_cors_request? && is_preflight_request? == bool }
|
93
|
-
|
93
|
+
end
|
94
94
|
|
95
95
|
app.options "*", is_cors_preflight: true do
|
96
|
-
|
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
|
104
|
+
|
105
|
+
pass if matches.size == 1
|
106
|
+
|
107
|
+
response.headers["Allow"] = matches.join " "
|
97
108
|
end
|
98
109
|
|
99
110
|
app.after do
|