mirror of
https://github.com/emikulic/darkhttpd.git
synced 2023-08-10 21:13:08 +03:00
Implement --forward-all to forward all requests to a given url.
Suggested and initially implemented by: Christian Hesse <mail@eworm.de>
This commit is contained in:
14
devel/cover
14
devel/cover
@ -31,7 +31,7 @@ python test.py
|
||||
kill $PID
|
||||
wait $PID
|
||||
|
||||
echo "===> run forwarding tests"
|
||||
echo "===> run --forward tests"
|
||||
./a.out $DIR --port $PORT \
|
||||
--forward example.com http://www.example.com \
|
||||
--forward secure.example.com https://www.example.com/secure >/dev/null &
|
||||
@ -41,7 +41,17 @@ python test_forward.py
|
||||
kill $PID
|
||||
wait $PID
|
||||
|
||||
echo "===> run no-server-id tests"
|
||||
echo "===> run --forward-all tests"
|
||||
./a.out $DIR --port $PORT \
|
||||
--forward example.com http://www.example.com \
|
||||
--forward-all http://catchall.example.com >/dev/null &
|
||||
PID=$!
|
||||
kill -0 $PID || exit 1
|
||||
python test_forward_all.py
|
||||
kill $PID
|
||||
wait $PID
|
||||
|
||||
echo "===> run --no-server-id tests"
|
||||
./a.out $DIR --port $PORT --no-server-id >/dev/null &
|
||||
PID=$!
|
||||
kill -0 $PID || exit 1
|
||||
|
27
devel/test_forward_all.py
Executable file
27
devel/test_forward_all.py
Executable file
@ -0,0 +1,27 @@
|
||||
#!/usr/bin/env python
|
||||
# This is run by the "cover" script.
|
||||
import unittest
|
||||
from test import TestHelper, Conn, parse
|
||||
|
||||
class TestForwardAll(TestHelper):
|
||||
def test_forward_root(self):
|
||||
resp = Conn().get("/", req_hdrs = { "Host": "not-example.com" })
|
||||
status, hdrs, body = parse(resp)
|
||||
self.assertContains(status, "301 Moved Permanently")
|
||||
expect = "http://catchall.example.com/"
|
||||
self.assertEquals(hdrs["Location"], expect)
|
||||
self.assertContains(body, expect)
|
||||
|
||||
def test_forward_relative(self):
|
||||
resp = Conn().get("/foo/bar",
|
||||
req_hdrs = { "Host": "still-not.example.com" })
|
||||
status, hdrs, body = parse(resp)
|
||||
self.assertContains(status, "301 Moved Permanently")
|
||||
expect = "http://catchall.example.com/foo/bar"
|
||||
self.assertEquals(hdrs["Location"], expect)
|
||||
self.assertContains(body, expect)
|
||||
|
||||
if __name__ == '__main__':
|
||||
unittest.main()
|
||||
|
||||
# vim:set ts=4 sw=4 et:
|
Reference in New Issue
Block a user