Skip to content

Commit 5a3bc1e

Browse files
committed
Merge pull request ruby-grape#116 from jwkoelewijn/frontier-vendoring
Frontier vendoring
2 parents f42b394 + 9447781 commit 5a3bc1e

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

lib/grape/middleware/versioner/header.rb

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,10 @@ def before
3535
env['api.subtype'] = subtype
3636

3737
subtype.scan(/vnd\.(.+)?-(.+)?\+(.*)?/) do |vendor, version, format|
38-
if options[:versions] && !options[:versions].include?(version)
38+
is_vendored = options[:version_options] && options[:version_options][:vendor]
39+
is_vendored_match = is_vendored ? options[:version_options][:vendor] == vendor : true
40+
41+
if (options[:versions] && !options[:versions].include?(version)) || !is_vendored_match
3942
throw :error, :status => 404, :headers => {'X-Cascade' => 'pass'}, :message => "404 API Version Not Found"
4043
end
4144

spec/grape/middleware/versioner/header_spec.rb

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,26 @@
8080
end
8181
end
8282

83+
context 'vendors' do
84+
before do
85+
@options = {
86+
:version => ['v1'],
87+
:version_options => {:using => :header, :vendor => 'vendor'}
88+
}
89+
end
90+
91+
it 'should match with correct vendor' do
92+
status = subject.call('HTTP_ACCEPT' => accept).first
93+
status.should == 200
94+
end
95+
96+
it 'should not match with an incorrect vendor' do
97+
expect {
98+
env = subject.call('HTTP_ACCEPT' => 'application/vnd.othervendor-v1+json').last
99+
}.to throw_symbol(:error, :status => 404, :headers => {'X-Cascade' => 'pass'}, :message => "404 API Version Not Found")
100+
end
101+
end
102+
83103
context 'no matched version' do
84104
before do
85105
@options = {

0 commit comments

Comments
 (0)