oxy 0.1.10 → 0.1.11

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: b1c9e36fe6c37d1b9d3fa3319998d949cdd1df3d
4
- data.tar.gz: 26093eb8b3a01ed4bcf05921510b6db5ab4e626c
3
+ metadata.gz: 8414aa2bc0fe1bd32e9a82242100afc5b834b6bc
4
+ data.tar.gz: 44df9d1db468f8dab50c432257216f7f83c6601d
5
5
  SHA512:
6
- metadata.gz: 67c8d1ac950fbb0740c2e86ae64c85de4a22daad553d06e5bfdb4f4a29fc2cf169b4ec7024d7bdd5e95452630179f7ba072c0e351b1b77474a48176511745679
7
- data.tar.gz: 6969b380b266179e1862d31e485b524500941ebb4286013cb154188a18750820e6a2e3efca811f6e85a0f8ca3bf8a1e71652b351741210b83989265e630d8b96
6
+ metadata.gz: 2ad33b86ebcf4b2fc86942961fa6b1627bc2f2290e180a682087e4377146e20c5b61d4986262ba623b683f1a08440fd66101566c67aa3221689f4ecd6fc52918
7
+ data.tar.gz: cc129435f205580ae34466b51eab7bb53560fb2bd9169835c8dd6f2173f94cc12c54d2ec2ae2419ce0052966c0de18668ea835fb45e0b9f699db6e1aea4bc4dd
data/lib/oxy.rb CHANGED
@@ -2,6 +2,8 @@ require "oxy/version"
2
2
 
3
3
  require "oxy/server"
4
4
  require "oxy/middleware/rsvp"
5
+ require "oxy/middleware/try_static"
6
+ require "oxy/middleware/custom_headers"
5
7
  require "oxy/module/subscribe"
6
8
  require "oxy/firebase/submissions"
7
9
  require "oxy/firebase/submission"
@@ -0,0 +1,28 @@
1
+ require "safe_yaml/load"
2
+
3
+ # Simple middleware to set custom http headers
4
+ class Oxy::CustomHeaders
5
+ def initialize(app, options)
6
+ @app, @custom_headers = app, load_from_file(options)
7
+ end
8
+
9
+ def call(env)
10
+ response = @app.call(env)
11
+ headers = Rack::Utils::HeaderHash.new(response[1])
12
+ response[1] = headers.merge(@custom_headers)
13
+ response
14
+ end
15
+
16
+ private
17
+ def load_from_file(options)
18
+ # parse custom headers from _config.yml
19
+ filename = File.join(options.document_root, "_config.yml")
20
+ conf = SafeYAML.load_file(filename) if File.exist?(filename)
21
+ # yield custom headers (if any)
22
+ if conf && conf.key?("webrick") && conf["webrick"]
23
+ headers = conf["webrick"]["headers"]
24
+ end
25
+ # default to empty headers (if necessary)
26
+ headers || {}
27
+ end
28
+ end
@@ -0,0 +1,21 @@
1
+ require "rack/contrib"
2
+
3
+ class Oxy::TryStatic < Rack::TryStatic
4
+ def initialize(app, options)
5
+ @app, @exclude = app, ["_config.yml"]
6
+ # call superclass
7
+ super(app, :root => options.document_root, :urls => %w[/], :try => [".html", "index.html", "/index.html"])
8
+ end
9
+
10
+ def call(env)
11
+ orig_path = env['PATH_INFO']
12
+ found = nil
13
+ # match requested path against excluded files
14
+ @exclude.each do |filename|
15
+ # detour Rack::TryStatic middleware by calling the next middleware in the pipeline
16
+ break if orig_path.end_with?(filename) && found = @app.call(env)
17
+ end
18
+ # pass thru or ask parent middleware to do the job
19
+ found or super(env)
20
+ end
21
+ end
@@ -43,10 +43,12 @@ module Oxy
43
43
  not_found_path = nil unless File.exist?(not_found_path)
44
44
  # build new app
45
45
  stack = Rack::Builder.new {
46
+ # middleware to handle custom HTTP headers
47
+ use Oxy::CustomHeaders, options
46
48
  # middleware to handle RSVP features
47
49
  use Oxy::RSVP, logger if options.rsvp
48
- # middleware to handle static resources
49
- use Rack::TryStatic, :root => options.document_root, :urls => %w[/], :try => [".html", "index.html", "/index.html"]
50
+ # middleware to handle static resources and prohibit access to the configuration files
51
+ use Oxy::TryStatic, options
50
52
  # fallback to 404 middleware as the main application
51
53
  run Rack::NotFound.new(not_found_path)
52
54
  }
@@ -1,3 +1,3 @@
1
1
  module Oxy
2
- VERSION = "0.1.10"
2
+ VERSION = "0.1.11"
3
3
  end
@@ -21,9 +21,10 @@ Gem::Specification.new do |spec|
21
21
 
22
22
  spec.add_runtime_dependency "rack", "~> 2.0"
23
23
  spec.add_runtime_dependency "rack-contrib", "~> 2.0.1"
24
- spec.add_runtime_dependency "puma", "~> 3.10"
24
+ spec.add_runtime_dependency "puma", "~> 3.11"
25
25
  spec.add_runtime_dependency "threaded", "~> 0.0.4"
26
26
  spec.add_runtime_dependency "httparty", "~> 0.15.6"
27
+ spec.add_runtime_dependency "safe_yaml", "~> 1.0.4"
27
28
 
28
29
  spec.add_development_dependency "bundler", "~> 1.15"
29
30
  spec.add_development_dependency "rake", "~> 10.0"
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: oxy
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.10
4
+ version: 0.1.11
5
5
  platform: ruby
6
6
  authors:
7
7
  - Pavel Tsurbeleu
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2018-01-02 00:00:00.000000000 Z
11
+ date: 2018-01-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rack
@@ -44,14 +44,14 @@ dependencies:
44
44
  requirements:
45
45
  - - "~>"
46
46
  - !ruby/object:Gem::Version
47
- version: '3.10'
47
+ version: '3.11'
48
48
  type: :runtime
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
52
  - - "~>"
53
53
  - !ruby/object:Gem::Version
54
- version: '3.10'
54
+ version: '3.11'
55
55
  - !ruby/object:Gem::Dependency
56
56
  name: threaded
57
57
  requirement: !ruby/object:Gem::Requirement
@@ -80,6 +80,20 @@ dependencies:
80
80
  - - "~>"
81
81
  - !ruby/object:Gem::Version
82
82
  version: 0.15.6
83
+ - !ruby/object:Gem::Dependency
84
+ name: safe_yaml
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 1.0.4
90
+ type: :runtime
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - "~>"
95
+ - !ruby/object:Gem::Version
96
+ version: 1.0.4
83
97
  - !ruby/object:Gem::Dependency
84
98
  name: bundler
85
99
  requirement: !ruby/object:Gem::Requirement
@@ -227,7 +241,9 @@ files:
227
241
  - lib/oxy.rb
228
242
  - lib/oxy/firebase/submission.rb
229
243
  - lib/oxy/firebase/submissions.rb
244
+ - lib/oxy/middleware/custom_headers.rb
230
245
  - lib/oxy/middleware/rsvp.rb
246
+ - lib/oxy/middleware/try_static.rb
231
247
  - lib/oxy/module/subscribe.rb
232
248
  - lib/oxy/server.rb
233
249
  - lib/oxy/version.rb