Skip to content

Commit

Permalink
Related to ruby-grape#133: the value of env[PATH_INFO] is no longer a…
Browse files Browse the repository at this point in the history
…ltered with path versioning. Got rid of the prefixer middleware, which is not generic across versioning schemes, but specific to the path versioner.
  • Loading branch information
dblock committed Jan 5, 2013
1 parent 548ceb4 commit c2936d8
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 58 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@
* [#172](https://github.com/intridea/grape/issues/172): Fix: MultiJson deprecated methods warnings - [@dblock](https://github.com/dblock).
* [#293](https://github.com/intridea/grape/pull/293): Added options to `cookies.delete`, enables passing a path - [@inst](https://github.com/inst).
* [#133](https://github.com/intridea/grape/issues/133): Fix: header-based versioning with use of `prefix` - [@seanmoon](https://github.com/seanmoon), [@dblock](https://github.com/dblock).
* [#133](https://github.com/intridea/grape/issues/133): The value of `env['PATH_INFO']` is no longer altered with `path` versioning - [@dblock](https://github.com/dblock).

* Your contribution here.

0.2.3 (24/12/2012)
Expand Down
1 change: 0 additions & 1 deletion lib/grape.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@ module Parser

module Middleware
autoload :Base, 'grape/middleware/base'
autoload :Prefixer, 'grape/middleware/prefixer'
autoload :Versioner, 'grape/middleware/versioner'
autoload :Formatter, 'grape/middleware/formatter'
autoload :Error, 'grape/middleware/error'
Expand Down
4 changes: 2 additions & 2 deletions lib/grape/endpoint.rb
Original file line number Diff line number Diff line change
Expand Up @@ -396,12 +396,12 @@ def build_middleware

b.use Rack::Auth::Basic, settings[:auth][:realm], &settings[:auth][:proc] if settings[:auth] && settings[:auth][:type] == :http_basic
b.use Rack::Auth::Digest::MD5, settings[:auth][:realm], settings[:auth][:opaque], &settings[:auth][:proc] if settings[:auth] && settings[:auth][:type] == :http_digest
b.use Grape::Middleware::Prefixer, :prefix => settings[:root_prefix] if settings[:root_prefix] && settings[:version] && settings[:version_options][:using] == :path

if settings[:version]
b.use Grape::Middleware::Versioner.using(settings[:version_options][:using]), {
:versions => settings[:version],
:version_options => settings[:version_options]
:version_options => settings[:version_options],
:prefix => settings[:root_prefix]
}
end

Expand Down
21 changes: 0 additions & 21 deletions lib/grape/middleware/prefixer.rb

This file was deleted.

17 changes: 15 additions & 2 deletions lib/grape/middleware/versioner/path.rb
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,14 @@ def default_options
end

def before
pieces = env['PATH_INFO'].split('/')
path = env['PATH_INFO']

if prefix && path.index(prefix) == 0
path.sub!(prefix, '')
path = Rack::Mount::Utils.normalize_path(path)
end

pieces = path.split('/')
potential_version = pieces[1]
if potential_version =~ options[:pattern]
if options[:versions] && !options[:versions].include?(potential_version)
Expand All @@ -33,9 +40,15 @@ def before

truncated_path = "/#{pieces[2..-1].join('/')}"
env['api.version'] = potential_version
env['PATH_INFO'] = truncated_path
end
end

private

def prefix
Rack::Mount::Utils.normalize_path(options[:prefix].to_s) if options[:prefix]
end

end
end
end
Expand Down
30 changes: 0 additions & 30 deletions spec/grape/middleware/prefixer_spec.rb

This file was deleted.

4 changes: 2 additions & 2 deletions spec/grape/middleware/versioner/path_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,8 +8,8 @@
subject.call('PATH_INFO' => '/v1/awesome').last.should == 'v1'
end

it 'cuts the version out of the path' do
subject.call('PATH_INFO' => '/v1/awesome')[1]['PATH_INFO'].should == '/awesome'
it 'does not cut the version out of the path' do
subject.call('PATH_INFO' => '/v1/awesome')[1]['PATH_INFO'].should == '/v1/awesome'
end

it 'provides a nil version if no path is given' do
Expand Down

0 comments on commit c2936d8

Please sign in to comment.