rack_slashless 0.0.1 → 0.0.2

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.
data/.gitignore ADDED
@@ -0,0 +1,18 @@
1
+ *.gem
2
+ *.rbc
3
+ .bundle
4
+ .config
5
+ coverage
6
+ InstalledFiles
7
+ lib/bundler/man
8
+ pkg
9
+ rdoc
10
+ spec/reports
11
+ test/tmp
12
+ test/version_tmp
13
+ tmp
14
+
15
+ # YARD artifacts
16
+ .yardoc
17
+ _yardoc
18
+ doc/
data/README.md ADDED
@@ -0,0 +1,2 @@
1
+ rack-slashless
2
+ ==============
@@ -0,0 +1,23 @@
1
+ module Rack
2
+ class Slashless
3
+
4
+ def initialize(app)
5
+ @app = app
6
+ end
7
+
8
+ def call(env)
9
+ if env['REQUEST_METHOD'] == "GET" && env['QUERY_STRING'].empty? && env['PATH_INFO'].end_with?("/")
10
+ parts = env['SERVER_NAME'].split('.')
11
+ suffix, chunk, prefix = parts.pop, parts.pop, parts.pop
12
+
13
+ destination = "#{env['rack.url_scheme']}://#{prefix}.#{chunk}.#{suffix}"
14
+ destination << "#{env['PATH_INFO']}"[0..-2]
15
+
16
+ [301, {'Location' => destination}, ['Redirecting to the same url but with the ending /']]
17
+ else
18
+ @app.call(env)
19
+ end
20
+ end
21
+
22
+ end
23
+ end
@@ -0,0 +1,15 @@
1
+ Gem::Specification.new do |gem|
2
+ gem.authors = ["Gregory Marcilhacy"]
3
+ gem.email = ["g.marcilhacy@gmail.com"]
4
+ gem.description = gem.summary = "Performs a 301 redirection on every url ending by a /"
5
+ gem.homepage = "https://github.com/gregorym/rack_slashless"
6
+
7
+ gem.files = `git ls-files | grep -v myapp`.split("\n")
8
+ gem.test_files = `git ls-files -- spec/*`.split("\n")
9
+ gem.name = "rack_slashless"
10
+ gem.require_paths = ["lib"]
11
+ gem.version = "0.0.2"
12
+
13
+ gem.add_development_dependency 'rspec'
14
+ gem.add_development_dependency 'rake-test'
15
+ end
@@ -0,0 +1,45 @@
1
+ require 'spec_helper'
2
+
3
+ describe Rack::Slashless do
4
+ def app
5
+ @app ||= Rack::Builder.new do
6
+ use Rack::Slashless
7
+ run lambda { |env| [200, { 'Content-Type' => 'text/plain' }, ['Hello World'] ] }
8
+ end
9
+ end
10
+
11
+ describe "/" do
12
+ it "should redirect to server name" do
13
+ get '/', {}, {'SERVER_NAME' => 'www.example.org'}
14
+
15
+ last_response.status.should == 301
16
+ last_response['Location'].should eql('http://www.example.org')
17
+ end
18
+ end
19
+
20
+ describe "/blog/" do
21
+ it "should redirect to /blog" do
22
+ get '/blog/', {}, {'SERVER_NAME' => 'www.example.org'}
23
+
24
+ last_response.status.should == 301
25
+ last_response['Location'].should eql('http://www.example.org/blog')
26
+ end
27
+ end
28
+
29
+ describe "/blog?article=1" do
30
+ it "should not redirect" do
31
+ get '/blog?article=1', {}, {'SERVER_NAME' => 'www.example.org'}
32
+
33
+ last_response.status.should == 200
34
+ end
35
+ end
36
+
37
+ describe "POST /blog" do
38
+ it "should not redirect" do
39
+ post '/blog/', {}, {'SERVER_NAME' => 'www.example.org'}
40
+
41
+ last_response.status.should == 200
42
+ end
43
+ end
44
+
45
+ end
@@ -0,0 +1,7 @@
1
+ ENV['RACK_ENV'] ||= 'test'
2
+ require 'rack_slashless'
3
+ require 'rack/test'
4
+
5
+ RSpec.configure do |config|
6
+ config.include(Rack::Test::Methods)
7
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: rack_slashless
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.1
4
+ version: 0.0.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -49,7 +49,13 @@ email:
49
49
  executables: []
50
50
  extensions: []
51
51
  extra_rdoc_files: []
52
- files: []
52
+ files:
53
+ - .gitignore
54
+ - README.md
55
+ - lib/rack_slashless.rb
56
+ - rack_slashless.gemspec
57
+ - spec/rack_slashless_spec.rb
58
+ - spec/spec_helper.rb
53
59
  homepage: https://github.com/gregorym/rack_slashless
54
60
  licenses: []
55
61
  post_install_message:
@@ -74,4 +80,6 @@ rubygems_version: 1.8.23
74
80
  signing_key:
75
81
  specification_version: 3
76
82
  summary: Performs a 301 redirection on every url ending by a /
77
- test_files: []
83
+ test_files:
84
+ - spec/rack_slashless_spec.rb
85
+ - spec/spec_helper.rb