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 +4 -4
- data/lib/oxy.rb +2 -0
- data/lib/oxy/middleware/custom_headers.rb +28 -0
- data/lib/oxy/middleware/try_static.rb +21 -0
- data/lib/oxy/server.rb +4 -2
- data/lib/oxy/version.rb +1 -1
- data/oxy.gemspec +2 -1
- metadata +20 -4
    
        checksums.yaml
    CHANGED
    
    | @@ -1,7 +1,7 @@ | |
| 1 1 | 
             
            ---
         | 
| 2 2 | 
             
            SHA1:
         | 
| 3 | 
            -
              metadata.gz:  | 
| 4 | 
            -
              data.tar.gz:  | 
| 3 | 
            +
              metadata.gz: 8414aa2bc0fe1bd32e9a82242100afc5b834b6bc
         | 
| 4 | 
            +
              data.tar.gz: 44df9d1db468f8dab50c432257216f7f83c6601d
         | 
| 5 5 | 
             
            SHA512:
         | 
| 6 | 
            -
              metadata.gz:  | 
| 7 | 
            -
              data.tar.gz:  | 
| 6 | 
            +
              metadata.gz: 2ad33b86ebcf4b2fc86942961fa6b1627bc2f2290e180a682087e4377146e20c5b61d4986262ba623b683f1a08440fd66101566c67aa3221689f4ecd6fc52918
         | 
| 7 | 
            +
              data.tar.gz: cc129435f205580ae34466b51eab7bb53560fb2bd9169835c8dd6f2173f94cc12c54d2ec2ae2419ce0052966c0de18668ea835fb45e0b9f699db6e1aea4bc4dd
         | 
    
        data/lib/oxy.rb
    CHANGED
    
    
| @@ -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
         | 
    
        data/lib/oxy/server.rb
    CHANGED
    
    | @@ -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  | 
| 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 | 
             
                  }
         | 
    
        data/lib/oxy/version.rb
    CHANGED
    
    
    
        data/oxy.gemspec
    CHANGED
    
    | @@ -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. | 
| 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. | 
| 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- | 
| 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. | 
| 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. | 
| 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
         |