2006-06-30 16:42:12 -04:00
|
|
|
# Copyright (c) 2005 Zed A. Shaw
|
|
|
|
# You can redistribute it and/or modify it under the same terms as Ruby.
|
|
|
|
#
|
|
|
|
# Additional work donated by contributors. See http://mongrel.rubyforge.org/attributions.html
|
|
|
|
# for more information.
|
|
|
|
|
2006-06-18 00:57:26 -04:00
|
|
|
require 'test/unit'
|
|
|
|
require 'mongrel'
|
|
|
|
require 'net/http'
|
|
|
|
require 'uri'
|
|
|
|
require 'timeout'
|
|
|
|
|
2006-06-21 01:09:18 -04:00
|
|
|
class RedirectHandlerTest < Test::Unit::TestCase
|
2006-06-18 00:57:26 -04:00
|
|
|
|
|
|
|
def setup
|
2006-06-21 01:09:18 -04:00
|
|
|
@server = Mongrel::HttpServer.new('127.0.0.1', 9998)
|
2006-06-18 00:57:26 -04:00
|
|
|
@server.run
|
2006-06-21 01:09:18 -04:00
|
|
|
@client = Net::HTTP.new('127.0.0.1', 9998)
|
2006-06-18 00:57:26 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
|
|
|
@server.stop
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_simple_redirect
|
|
|
|
tester = Mongrel::RedirectHandler.new('/yo')
|
|
|
|
@server.register("/test", tester)
|
|
|
|
|
|
|
|
sleep(1)
|
|
|
|
res = @client.request_get('/test')
|
|
|
|
assert res != nil, "Didn't get a response"
|
|
|
|
assert_equal ['/yo'], res.get_fields('Location')
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_rewrite
|
|
|
|
tester = Mongrel::RedirectHandler.new(/(\w+)/, '+\1+')
|
|
|
|
@server.register("/test", tester)
|
|
|
|
|
|
|
|
sleep(1)
|
|
|
|
res = @client.request_get('/test/something')
|
|
|
|
assert_equal ['/+test+/+something+'], res.get_fields('Location')
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
|