rack-cors 2.0.0.rc1 → 2.0.1

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.

checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: c4c9bf1e801f0bb5f4c5abb111fbe9a0dcfbd1bcf0da1b2070fb1575de5bcdd7
4
- data.tar.gz: 9a78208ad501ffa452ac0721eeb29ccf5fc00ad392bfe2be06c8d0c6a4a1c5c0
3
+ metadata.gz: f47b5b2ba34721795ddb1c65e70e989134655e7f47116dd977edee702a79f41f
4
+ data.tar.gz: 7c03dc701b00b7418ab4d733872fccc3522392f0f85014b8ca25045767d866a9
5
5
  SHA512:
6
- metadata.gz: ef9c38f1c3f6c13609afcded7d3bd0c40e22e6a098fe7f565d5d6351c1ed0e3f199752912163bd1963005b3ed4d5ae20216b6f8c94736b5f941d9e038e089829
7
- data.tar.gz: 633bf8887b580a52cd0f50359d8febffd609190cbb5084ae5e02233126c14a70d019bdfd2feddba7cf078cf5d820e86856ad867fcbc1ce90bd3ecb9c75b08f64
6
+ metadata.gz: d5a94b8f282fd5367e125f4b49e18ce5fb1c07581d89b2d50dc8cf4eb70e8404d97c78a6ccaf90f1e41f0f220bb09ff9dd07a4677559935cc35256674e6c512d
7
+ data.tar.gz: bee187e2dc53281d8b454df32b6a8fd50e05b66de4f25649d74f176abf29d52eb4cee5a2b2e602e087c5f5805b6dd55ab86a9e0692d3d82c5538e0c30e3c020b
@@ -0,0 +1,39 @@
1
+ name: ci
2
+
3
+ on:
4
+ - push
5
+ - pull_request
6
+
7
+ jobs:
8
+ test:
9
+ strategy:
10
+ fail-fast: false
11
+ matrix:
12
+ ruby:
13
+ - "2.3"
14
+ - "2.4"
15
+ - "2.5"
16
+ - "2.6"
17
+ - "2.7"
18
+ - "3.0"
19
+ - "3.1"
20
+ - "3.2"
21
+ - truffleruby-head
22
+ runs-on: ubuntu-latest
23
+ steps:
24
+ - uses: actions/checkout@v3
25
+ - uses: ruby/setup-ruby@v1
26
+ with:
27
+ ruby-version: ${{ matrix.ruby }}
28
+ bundler-cache: true
29
+ - run: bundle exec rake test
30
+
31
+ rubocop:
32
+ runs-on: ubuntu-latest
33
+ steps:
34
+ - uses: actions/checkout@v3
35
+ - uses: ruby/setup-ruby@v1
36
+ with:
37
+ ruby-version: 3.2.1
38
+ bundler-cache: true
39
+ - run: bundle exec rubocop
data/.rubocop.yml CHANGED
@@ -1,8 +1,8 @@
1
1
  ---
2
-
3
2
  AllCops:
4
3
  Exclude:
5
- - 'examples/**/*'
4
+ - "examples/**/*"
5
+ - "vendor/**/*"
6
6
 
7
7
  # Disables
8
8
  Layout/LineLength:
data/CHANGELOG.md CHANGED
@@ -1,11 +1,16 @@
1
1
  # Change Log
2
2
  All notable changes to this project will be documented in this file.
3
3
 
4
- ## 2.0.0 - 2022-09-11
4
+ ## 2.0.1 - 2023-02-17
5
+ ### Changed
6
+ - Use Rack::Utils::HeaderHash when Rack 2.x is detected
7
+
8
+ ## 2.0.0 - 2023-02-14
5
9
  ### Changed
6
10
  - Refactored codebase
7
11
  - Support declaring custom protocols in origin
8
12
  - Lowercased header names as defined by Rack spec
13
+ - Fix issue with duplicate headers because of header name case
9
14
 
10
15
  ## 1.1.1 - 2019-12-29
11
16
  ### Changed
data/README.md CHANGED
@@ -1,8 +1,8 @@
1
- # Rack CORS Middleware [![Build Status](https://travis-ci.org/cyu/rack-cors.svg?branch=master)](https://travis-ci.org/cyu/rack-cors)
1
+ # Rack CORS Middleware [![Build Status](https://github.com/cyu/rack-cors/actions/workflows/ci.yaml/badge.svg)](https://github.com/cyu/rack-cors/actions)
2
2
 
3
3
  `Rack::Cors` provides support for Cross-Origin Resource Sharing (CORS) for Rack compatible web applications.
4
4
 
5
- The [CORS spec](http://www.w3.org/TR/cors/) allows web applications to make cross domain AJAX calls without using workarounds such as JSONP. See [Cross-domain Ajax with Cross-Origin Resource Sharing](http://www.nczonline.net/blog/2010/05/25/cross-domain-ajax-with-cross-origin-resource-sharing/)
5
+ The [CORS spec](http://www.w3.org/TR/cors/) allows web applications to make cross domain AJAX calls without using workarounds such as JSONP. See [further explanations on MDN](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS)
6
6
 
7
7
  ## Installation
8
8
 
@@ -33,6 +33,8 @@ Rails.application.config.middleware.insert_before 0, Rack::Cors do
33
33
  end
34
34
  ```
35
35
 
36
+ NOTE: If you create application with `--api` option, configuration automatically generate in `config/initializers/cors.rb`.
37
+
36
38
  We use `insert_before` to make sure `Rack::Cors` runs at the beginning of the stack to make sure it isn't interfered with by other middleware (see `Rack::Cache` note in **Common Gotchas** section). Basic setup examples for Rails 5 & Rails 6 can be found in the examples/ directory.
37
39
 
38
40
  See The [Rails Guide to Rack](http://guides.rubyonrails.org/rails_on_rack.html) for more details on rack middlewares or watch the [railscast](http://railscasts.com/episodes/151-rack-middleware).
@@ -147,3 +149,12 @@ RAILS_ENV=production bundle exec rake middleware
147
149
  If you trying to serve CORS headers on static assets (like CSS, JS, Font files), keep in mind that static files are usually served directly from web servers and never runs through the Rails container (including the middleware stack where `Rack::Cors` resides).
148
150
 
149
151
  In Heroku, you can serve static assets through the Rails container by setting `config.serve_static_assets = true` in `production.rb`.
152
+
153
+ ### Custom Protocols (chrome-extension://, ionic://, etc.)
154
+
155
+ Prior to 2.0.0, `http://`, `https://`, and `file://` are the only protocols supported in the `origins` list. If you wish to specify an origin that
156
+ has a custom protocol (`chrome-extension://`, `ionic://`, etc.) simply exclude the protocol. [See issue.](https://github.com/cyu/rack-cors/issues/100)
157
+
158
+ For example, instead of specifying `chrome-extension://aomjjhallfgjeglblehebfpbcfeobpga` specify `aomjjhallfgjeglblehebfpbcfeobpga` in `origins`.
159
+
160
+ As of 2.0.0 (currently in RC1), you can specify origins with a custom protocol.
@@ -66,7 +66,7 @@ module Rack
66
66
  'access-control-max-age' => max_age.to_s
67
67
  }
68
68
  h['access-control-allow-credentials'] = 'true' if credentials
69
- h
69
+ header_proc.call(h)
70
70
  end
71
71
 
72
72
  protected
@@ -83,7 +83,7 @@ module Rack
83
83
 
84
84
  def to_preflight_headers(env)
85
85
  h = to_headers(env)
86
- h.merge!('Access-Control-Allow-Headers' => env[Rack::Cors::HTTP_ACCESS_CONTROL_REQUEST_HEADERS]) if env[Rack::Cors::HTTP_ACCESS_CONTROL_REQUEST_HEADERS]
86
+ h.merge!('access-control-allow-headers' => env[Rack::Cors::HTTP_ACCESS_CONTROL_REQUEST_HEADERS]) if env[Rack::Cors::HTTP_ACCESS_CONTROL_REQUEST_HEADERS]
87
87
  h
88
88
  end
89
89
 
@@ -127,6 +127,16 @@ module Rack
127
127
  raise TypeError, path
128
128
  end
129
129
  end
130
+
131
+ def header_proc
132
+ @header_proc ||= begin
133
+ if defined?(Rack::Headers)
134
+ ->(h) { h }
135
+ else
136
+ ->(h) { Rack::Utils::HeaderHash.new(h) }
137
+ end
138
+ end
139
+ end
130
140
  end
131
141
  end
132
142
  end
@@ -2,6 +2,6 @@
2
2
 
3
3
  module Rack
4
4
  class Cors
5
- VERSION = '2.0.0.rc1'
5
+ VERSION = '2.0.1'
6
6
  end
7
7
  end
data/rack-cors.gemspec CHANGED
@@ -24,7 +24,7 @@ Gem::Specification.new do |spec|
24
24
  spec.add_development_dependency 'minitest', '~> 5.11.0'
25
25
  spec.add_development_dependency 'mocha', '~> 1.6.0'
26
26
  spec.add_development_dependency 'pry', '~> 0.12'
27
- spec.add_development_dependency 'rack-test', '~> 1.1.0'
27
+ spec.add_development_dependency 'rack-test', '>= 1.1.0'
28
28
  spec.add_development_dependency 'rake', '~> 12.3.0'
29
29
  spec.add_development_dependency 'rubocop', '~> 0.80.1'
30
30
  end
@@ -70,7 +70,7 @@ describe Rack::Cors do
70
70
  use FakeProxy if options[:proxy]
71
71
  map('/') do
72
72
  run(lambda do |_env|
73
- [200, { 'Content-Type' => 'text/html' }, ['success']]
73
+ [200, { 'content-type' => 'text/html' }, ['success']]
74
74
  end)
75
75
  end
76
76
  end
@@ -428,7 +428,7 @@ describe Rack::Cors do
428
428
  @app ||= Rack::Builder.new do
429
429
  use Rack::Cors
430
430
  use Rack::Lint
431
- run ->(_env) { [200, { 'Content-Type' => 'text/html' }, ['hello']] }
431
+ run ->(_env) { [200, { 'content-type' => 'text/html' }, ['hello']] }
432
432
  end
433
433
  end
434
434
 
@@ -474,7 +474,7 @@ describe Rack::Cors do
474
474
  end
475
475
  end
476
476
  map('/') do
477
- run ->(_env) { [200, { 'Content-Type' => 'text/html' }, ['hello']] }
477
+ run ->(_env) { [200, { 'content-type' => 'text/html' }, ['hello']] }
478
478
  end
479
479
  end
480
480
  end
@@ -495,7 +495,7 @@ describe Rack::Cors do
495
495
  end
496
496
  end
497
497
  map('/') do
498
- run ->(_env) { [200, { 'Content-Type' => 'text/html' }, ['hello']] }
498
+ run ->(_env) { [200, { 'content-type' => 'text/html' }, ['hello']] }
499
499
  end
500
500
  end
501
501
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack-cors
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.rc1
4
+ version: 2.0.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Calvin Yu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2022-09-11 00:00:00.000000000 Z
11
+ date: 2023-03-17 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -90,14 +90,14 @@ dependencies:
90
90
  name: rack-test
91
91
  requirement: !ruby/object:Gem::Requirement
92
92
  requirements:
93
- - - "~>"
93
+ - - ">="
94
94
  - !ruby/object:Gem::Version
95
95
  version: 1.1.0
96
96
  type: :development
97
97
  prerelease: false
98
98
  version_requirements: !ruby/object:Gem::Requirement
99
99
  requirements:
100
- - - "~>"
100
+ - - ">="
101
101
  - !ruby/object:Gem::Version
102
102
  version: 1.1.0
103
103
  - !ruby/object:Gem::Dependency
@@ -136,8 +136,8 @@ executables: []
136
136
  extensions: []
137
137
  extra_rdoc_files: []
138
138
  files:
139
+ - ".github/workflows/ci.yaml"
139
140
  - ".rubocop.yml"
140
- - ".travis.yml"
141
141
  - CHANGELOG.md
142
142
  - Gemfile
143
143
  - LICENSE.txt
@@ -177,11 +177,11 @@ required_ruby_version: !ruby/object:Gem::Requirement
177
177
  version: '0'
178
178
  required_rubygems_version: !ruby/object:Gem::Requirement
179
179
  requirements:
180
- - - ">"
180
+ - - ">="
181
181
  - !ruby/object:Gem::Version
182
- version: 1.3.1
182
+ version: '0'
183
183
  requirements: []
184
- rubygems_version: 3.3.10
184
+ rubygems_version: 3.3.26
185
185
  signing_key:
186
186
  specification_version: 4
187
187
  summary: Middleware for enabling Cross-Origin Resource Sharing in Rack apps
data/.travis.yml DELETED
@@ -1,13 +0,0 @@
1
- language: ruby
2
- sudo: false
3
- rvm:
4
- - 2.3
5
- - 2.4
6
- - 2.5
7
- - 2.6
8
- - 2.7
9
- - truffleruby-head
10
-
11
- script:
12
- - bundle exec rubocop
13
- - bundle exec rake test