rack-slash_merger 0.1.0

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 ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 43e189907430f6c2602fab641f58f0da698c5491
4
+ data.tar.gz: 80d9651b473398b059d824843d9c7852fa0e7a71
5
+ SHA512:
6
+ metadata.gz: e4f7d9cc8124d3d20fcc6175b5347d2f382ec540dce545fcb81da57501b4bd07ad65dd90892d42e5b26b4c2bf219b8db2192de1f4844fff0bd386ad9eeca3430
7
+ data.tar.gz: c26d3a37c4b8d29381c015fce14dc5520f74a6db6142e7b8df01f90c2387a0b54d20dabbc2d7aba21139a4f0598b7db00c5439d8bd39b0542a4704374a586a0b
data/.gitignore ADDED
@@ -0,0 +1,2 @@
1
+ *.gem
2
+ Gemfile.lock
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - "2.2.0"
4
+ matrix:
5
+ include:
data/Gemfile ADDED
@@ -0,0 +1,5 @@
1
+ source 'http://rubygems.org'
2
+
3
+ gem 'rake'
4
+
5
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,19 @@
1
+ Copyright (c) 2015 by Adrian Lehmann
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining a copy
4
+ of this software and associated documentation files (the "Software"), to deal
5
+ in the Software without restriction, including without limitation the rights
6
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7
+ copies of the Software, and to permit persons to whom the Software is
8
+ furnished to do so, subject to the following conditions:
9
+
10
+ The above copyright notice and this permission notice shall be included in
11
+ all copies or substantial portions of the Software.
12
+
13
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,35 @@
1
+ # rack-slash_merger [![Build Status](https://travis-ci.org/ownadi/rack-slash_merger.svg?branch=master)](https://travis-ci.org/ownadi/rack-slash_merger)
2
+
3
+ A rack middleware for compressing of two or more adjacent slashes in a URI into a single slash.
4
+
5
+ ## Usage
6
+
7
+ ### Rails
8
+
9
+ Just add the gem to your gemfile and run bundle
10
+
11
+ ```ruby
12
+ gem 'rack-slash_merger'
13
+ ```
14
+
15
+ Then restart your Rails server. No configuration is needed. The gem simply hooks itself into the Rack middleware call stack.
16
+
17
+ ### Other rack-based application
18
+
19
+ In your Gemfile you add the gem:
20
+
21
+ ```ruby
22
+ gem 'rack-slash_merger'
23
+ ```
24
+
25
+ Add middleware to stack:
26
+
27
+ ```ruby
28
+ # config.ru
29
+ include 'rack/slash_merger'
30
+ use Rack::SlashMerger
31
+ ```
32
+
33
+ ## License
34
+
35
+ MIT License. Copyright 2015 Adrian Lehmann
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require 'rspec/core/rake_task'
3
+
4
+ RSpec::Core::RakeTask.new
5
+
6
+ task :default => :spec
@@ -0,0 +1,2 @@
1
+ require 'rack/slash_merger'
2
+ require 'rack/slash_merger/railtie' if defined?(Rails)
@@ -0,0 +1,18 @@
1
+ module Rack
2
+ class SlashMerger
3
+ PATTERN = %r{//+}
4
+
5
+ def initialize(app)
6
+ @app = app
7
+ end
8
+
9
+ def call(env)
10
+ if env['PATH_INFO'] =~ PATTERN
11
+ env['PATH_INFO'].gsub!(PATTERN, '/')
12
+ [301, {"Location" => Rack::Request.new(env).url, "Content-Type" => ""}, []]
13
+ else
14
+ @app.call(env)
15
+ end
16
+ end
17
+ end
18
+ end
@@ -0,0 +1,9 @@
1
+ module Rack
2
+ class SlashMerger
3
+ class Railtie < ::Rails::Railtie
4
+ initializer 'slash_merger.insert_middleware' do |app|
5
+ app.config.middleware.use "Rack::SlashMerger"
6
+ end
7
+ end
8
+ end
9
+ end
@@ -0,0 +1,5 @@
1
+ module Rack
2
+ class SlashMerger
3
+ VERSION = '0.1.0'
4
+ end
5
+ end
@@ -0,0 +1,16 @@
1
+ require_relative 'lib/rack/slash_merger/version'
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = 'rack-slash_merger'
5
+ s.version = Rack::SlashMerger::VERSION
6
+ s.summary = 'Rack-based slash merger'
7
+ s.description = 'Rack-based compression of two or more adjacent slashes in a URI into a single slash.'
8
+ s.files = `git ls-files`.split($/)
9
+ s.require_path = 'lib'
10
+ s.author = 'Adrian Lehmann'
11
+ s.email = 'ownadi@gmail.com'
12
+ s.homepage = 'https://github.com/ownadi/rack-slash_merger'
13
+ s.license = 'MIT'
14
+ s.add_dependency 'rack'
15
+ s.add_development_dependency 'rspec'
16
+ end
@@ -0,0 +1,19 @@
1
+ require 'rack/mock'
2
+ require_relative '../lib/rack/slash_merger'
3
+
4
+ describe Rack::SlashMerger do
5
+ let(:app) { proc{[200, {}, ['Hello, world.']]} }
6
+ let(:stack) { Rack::SlashMerger.new(app) }
7
+ let(:request) { Rack::MockRequest.new(stack) }
8
+
9
+ context 'when uri contains two or more adjacent slashes' do
10
+ let(:response) { request.get('/p/a//t///h') }
11
+ it { expect(response.status).to eql(301) }
12
+ it { expect(response.headers['Location']).to include('/p/a/t/h')}
13
+ end
14
+
15
+ context 'when uri does not contain two or more adjacent slashes' do
16
+ let(:response) { request.get('/p/a/t/h') }
17
+ it { expect(response.status).to eql(200) }
18
+ end
19
+ end
metadata ADDED
@@ -0,0 +1,84 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rack-slash_merger
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Adrian Lehmann
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2015-11-18 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: rack
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rspec
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ description: Rack-based compression of two or more adjacent slashes in a URI into
42
+ a single slash.
43
+ email: ownadi@gmail.com
44
+ executables: []
45
+ extensions: []
46
+ extra_rdoc_files: []
47
+ files:
48
+ - ".gitignore"
49
+ - ".travis.yml"
50
+ - Gemfile
51
+ - LICENSE
52
+ - README.md
53
+ - Rakefile
54
+ - lib/rack-slash_merger.rb
55
+ - lib/rack/slash_merger.rb
56
+ - lib/rack/slash_merger/railtie.rb
57
+ - lib/rack/slash_merger/version.rb
58
+ - rack-slash_merger.gemspec
59
+ - spec/rack-slash_merger_spec.rb
60
+ homepage: https://github.com/ownadi/rack-slash_merger
61
+ licenses:
62
+ - MIT
63
+ metadata: {}
64
+ post_install_message:
65
+ rdoc_options: []
66
+ require_paths:
67
+ - lib
68
+ required_ruby_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: '0'
73
+ required_rubygems_version: !ruby/object:Gem::Requirement
74
+ requirements:
75
+ - - ">="
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ requirements: []
79
+ rubyforge_project:
80
+ rubygems_version: 2.4.8
81
+ signing_key:
82
+ specification_version: 4
83
+ summary: Rack-based slash merger
84
+ test_files: []