1
0
Fork 0
mirror of https://github.com/sinatra/sinatra synced 2023-03-27 23:18:01 -04:00

filter on host

This commit is contained in:
Blake Mizerany 2008-04-01 18:20:52 -07:00
parent 370bda3e53
commit d71fe8303d
2 changed files with 46 additions and 2 deletions

View file

@ -160,10 +160,13 @@ module Sinatra
def invoke(request)
params = {}
if options[:agent]
return unless request.user_agent =~ options[:agent]
if agent = options[:agent]
return unless request.user_agent =~ agent
params[:agent] = $~[1..-1]
end
if host = options[:host]
return unless host === request.host
end
return unless pattern =~ request.path_info.squeeze('/')
params.merge!(param_keys.zip($~.captures.map(&:from_param)).to_hash)
Result.new(block, params, 200)

41
test/diddy_test.rb Normal file
View file

@ -0,0 +1,41 @@
require File.dirname(__FILE__) + '/helper'
context "Diddy" do
setup do
Sinatra.application = nil
end
specify "should map urls to different apps" do
get '/' do
'asdf'
end
get_it '/'
assert ok?
assert_equal('asdf', body)
get '/foo', :host => 'foo.sinatrarb.com' do
'in foo!'
end
get '/foo', :host => 'bar.sinatrarb.com' do
'in bar!'
end
get_it '/foo', {}, 'HTTP_HOST' => 'foo.sinatrarb.com'
assert ok?
assert_equal 'in foo!', body
get_it '/foo', {}, 'HTTP_HOST' => 'bar.sinatrarb.com'
assert ok?
assert_equal 'in bar!', body
get_it '/foo'
assert not_found?
end
end