hobby-cors 0.0.0 → 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +4 -4
  2. data/lib/hobby/cors.rb +30 -5
  3. metadata +14 -13
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 494fee694e14e61b1aecc95e43b752d51aa0e1bafdc8f7072bd49a281273e8c0
4
- data.tar.gz: 387d2c9722827471b5623e1faca1dd129dd4a931dc6f7c1a3eec3cd1fc191a72
3
+ metadata.gz: d5e015f024ff9151f35aa4cf941f75ce9480c83984a0617dd12d56c991bdd8c7
4
+ data.tar.gz: 7e693bc6293c8388293cf400b8a8b42574be5aecd1e9f8c6b34b6f4110ec12c0
5
5
  SHA512:
6
- metadata.gz: 13283068cf585bb0465dc3dea3c62f6b6345e70b06a8be76b0d3bf55db41350b72d29cff8907e8e1323936454f66f459d93cce6a91ab79ec484e60e8838ac300
7
- data.tar.gz: 558c4f85d9981d7262fcaa1dea50f270d25b458eb0b4359613a99586109007e089e0546f70c34cf94273d84060f9910cdcb5035785cc78e9fc9f5716a85ce597
6
+ metadata.gz: 5b73e2f5d700a708de2da36f5a7d09014fe944147d33742008b09542cae239b993cbf9578acd5106d8d42561acb2f7a3d6d114fa0807e344f016d51bb788bb4a
7
+ data.tar.gz: 5078de1fd7f111cc68c5bbb680396b63bfa1696efb33533c044038e8081a7d4327d5df349b4f761edd4bc7d71a1c5688cd42ccae28542464a9dc37a8c629b06c
data/lib/hobby/cors.rb CHANGED
@@ -1,13 +1,38 @@
1
+ require 'rack'
2
+
1
3
  module Hobby
2
- class Cors
3
- def initialize app
4
+ class CORS
5
+ def initialize app, origins: nil
4
6
  @app = app
7
+ @origins = origins
5
8
  end
6
9
 
7
10
  def call env
8
- status, headers, body = @app.call env
9
- headers['Access-Control-Allow-Origin'] = '*'
10
- [status, headers, body]
11
+ origin = '*'
12
+
13
+ if @origins
14
+ if @origins.include? env['HTTP_ORIGIN']
15
+ origin = env['HTTP_ORIGIN']
16
+ else
17
+ return [400, {}, []]
18
+ end
19
+ end
20
+
21
+ case env['REQUEST_METHOD']
22
+ when 'OPTIONS'
23
+ response = Rack::Response.new
24
+
25
+ response.add_header 'Access-Control-Allow-Origin', origin
26
+ response.add_header 'Access-Control-Allow-Methods', 'POST, OPTIONS'
27
+ response.add_header 'Access-Control-Allow-Headers', 'Authorization, Content-Type'
28
+ response.add_header 'Access-Control-Max-Age', '86400'
29
+
30
+ response.to_a
31
+ else
32
+ status, headers, body = @app.call env
33
+ headers['Access-Control-Allow-Origin'] = origin
34
+ [status, headers, body]
35
+ end
11
36
  end
12
37
  end
13
38
  end
metadata CHANGED
@@ -1,38 +1,40 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hobby-cors
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.0
4
+ version: 0.1.0
5
5
  platform: ruby
6
6
  authors:
7
- - Anatoly Chernow
7
+ - Anatoly Chernov
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-06-05 00:00:00.000000000 Z
11
+ date: 2021-04-28 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ">="
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '0'
19
+ version: '2'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ">="
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '0'
26
+ version: '2'
27
27
  description:
28
- email:
28
+ email:
29
+ - chertoly@gmail.com
29
30
  executables: []
30
31
  extensions: []
31
32
  extra_rdoc_files: []
32
33
  files:
33
34
  - lib/hobby/cors.rb
34
- homepage:
35
- licenses: []
35
+ homepage: https://github.com/ch1c0t/hobby-cors
36
+ licenses:
37
+ - ISC
36
38
  metadata: {}
37
39
  post_install_message:
38
40
  rdoc_options: []
@@ -49,9 +51,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
49
51
  - !ruby/object:Gem::Version
50
52
  version: '0'
51
53
  requirements: []
52
- rubyforge_project:
53
- rubygems_version: 2.7.6
54
+ rubygems_version: 3.1.6
54
55
  signing_key:
55
56
  specification_version: 4
56
- summary: A Rack CORS middleware without complexities.
57
+ summary: A Rack middleware for CORS, with permissive defaults.
57
58
  test_files: []