rack-cors 0.2.0 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.

Potentially problematic release.


This version of rack-cors might be problematic. Click here for more details.

data/README.rdoc CHANGED
@@ -13,6 +13,10 @@ http://www.w3.org/TR/access-control/#simple-cross-origin-request-and-actual-r
13
13
  Install the gem:
14
14
 
15
15
  gem install rack-cors
16
+
17
+ In your Gemfile:
18
+
19
+ gem 'rack-cors', :require => 'rack/cors'
16
20
 
17
21
 
18
22
  == Configuration
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.2.0
1
+ 0.2.2
data/lib/rack/cors.rb CHANGED
@@ -43,7 +43,7 @@ module Rack
43
43
  protected
44
44
  def debug(env, message = nil, &block)
45
45
  logger = @logger || env['rack.logger'] || begin
46
- @logger = ::Logger.new(STDOUT).tap {|logger| logger.level = ::Logger::Severity::DEBUG}
46
+ @logger = ::Logger.new(STDOUT).tap {|logger| logger.level = ::Logger::Severity::INFO}
47
47
  end
48
48
  logger.debug(message, &block)
49
49
  end
@@ -129,7 +129,7 @@ module Rack
129
129
 
130
130
  def process_preflight(env)
131
131
  return nil if invalid_method_request?(env) || invalid_headers_request?(env)
132
- to_preflight_headers(env)
132
+ {'Content-Type' => 'text/plain'}.merge(to_preflight_headers(env))
133
133
  end
134
134
 
135
135
  def to_headers(env)
@@ -165,7 +165,10 @@ module Rack
165
165
 
166
166
  def allow_headers?(request_headers)
167
167
  return false if headers.nil?
168
- headers == :any || !request_headers.detect{|h| !headers.include?(h.downcase)}
168
+ headers == :any || begin
169
+ request_headers = request_headers.split(/,\s*/) if request_headers.kind_of?(String)
170
+ request_headers.all?{|h| headers.include?(h.downcase)}
171
+ end
169
172
  end
170
173
 
171
174
  def ensure_enum(v)
data/rack-cors.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{rack-cors}
8
- s.version = "0.2.0"
8
+ s.version = "0.2.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Calvin Yu"]
12
- s.date = %q{2010-06-08}
12
+ s.date = %q{2010-08-26}
13
13
  s.email = %q{csyu77@gmail.com}
14
14
  s.extra_rdoc_files = [
15
15
  "README.rdoc"
data/test/cors_test.rb CHANGED
@@ -51,11 +51,27 @@ class CorsTest < Test::Unit::TestCase
51
51
  assert_preflight_success
52
52
  end
53
53
 
54
+ should 'allow multiple headers match' do
55
+ # Webkit style
56
+ preflight_request('http://localhost:3000', '/two_headers', :headers => 'X-Requested-With, X-Domain-Token')
57
+ assert_preflight_success
58
+
59
+ # Gecko style
60
+ preflight_request('http://localhost:3000', '/two_headers', :headers => 'x-requested-with,x-domain-token')
61
+ assert_preflight_success
62
+ end
63
+
54
64
  should '* origin should allow any origin' do
55
65
  preflight_request('http://locohost:3000', '/public')
56
66
  assert_preflight_success
57
67
  assert_equal '*', last_response.headers['Access-Control-Allow-Origin']
58
68
  end
69
+
70
+ should 'return a Content-Type' do
71
+ preflight_request('http://localhost:3000', '/')
72
+ assert_preflight_success
73
+ assert_not_nil last_response.headers['Content-Type']
74
+ end
59
75
  end
60
76
 
61
77
  protected
@@ -65,7 +81,7 @@ class CorsTest < Test::Unit::TestCase
65
81
  header 'Access-Control-Request-Method', opts[:method] ? opts[:method].to_s.upcase : 'GET'
66
82
  end
67
83
  if opts[:headers]
68
- header 'Access-Control-Request-Headers', [opts[:headers]].flatten.join(', ')
84
+ header 'Access-Control-Request-Headers', opts[:headers]
69
85
  end
70
86
  options path
71
87
  end
data/test/test.ru CHANGED
@@ -7,6 +7,7 @@ use Rack::Cors do |cfg|
7
7
  allow.resource '/get-only', :methods => :get
8
8
  allow.resource '/', :headers => :any
9
9
  allow.resource '/single_header', :headers => 'x-domain-token'
10
+ allow.resource '/two_headers', :headers => %w{x-domain-token x-requested-with}
10
11
  # allow.resource '/file/at/*',
11
12
  # :methods => [:get, :post, :put, :delete],
12
13
  # :headers => :any,
metadata CHANGED
@@ -1,13 +1,13 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-cors
3
3
  version: !ruby/object:Gem::Version
4
- hash: 23
4
+ hash: 19
5
5
  prerelease: false
6
6
  segments:
7
7
  - 0
8
8
  - 2
9
- - 0
10
- version: 0.2.0
9
+ - 2
10
+ version: 0.2.2
11
11
  platform: ruby
12
12
  authors:
13
13
  - Calvin Yu
@@ -15,7 +15,7 @@ autorequire:
15
15
  bindir: bin
16
16
  cert_chain: []
17
17
 
18
- date: 2010-06-08 00:00:00 -04:00
18
+ date: 2010-08-26 00:00:00 -04:00
19
19
  default_executable:
20
20
  dependencies: []
21
21