Add test for --forward
[darkhttpd] / devel / test_forward.py
1 #!/usr/bin/env python
2 import unittest
3 from test import TestHelper, Conn, parse
4
5 class TestForward(TestHelper):
6 def test_forward_root(self):
7 resp = Conn().get("/", req_hdrs = { "Host": "example.com" })
8 status, hdrs, body = parse(resp)
9 self.assertContains(status, "301 Moved Permanently")
10 expect = "http://www.example.com/"
11 self.assertEquals(hdrs["Location"], expect)
12 self.assertContains(body, expect)
13
14 def test_forward_relative(self):
15 resp = Conn().get("/foo/bar",
16 req_hdrs = { "Host": "secure.example.com" })
17 status, hdrs, body = parse(resp)
18 self.assertContains(status, "301 Moved Permanently")
19 expect = "https://www.example.com/secure/foo/bar"
20 self.assertEquals(hdrs["Location"], expect)
21 self.assertContains(body, expect)
22
23 if __name__ == '__main__':
24 unittest.main()
25
26 # vim:set ts=4 sw=4 et: